我有一个加载正确这样的样式表的成分:Angular 2 - 如何有条件地向我的组件添加样式?
@Component({
selector: 'open-account',
styleUrls: ['open-account.component.scss'],
templateUrl: './open-account.component.html',
})
我想如果字符串widget=true
是出现在URL,但无论如何不能去工作,有条件地加载另一个样式表。我曾尝试:
var stylesArr = ['open-account.component.scss'];
if (window.location.href.indexOf('widget=true') > -1) stylesArr.push('open-account-widget-styles.component.scss');
@Component({
selector: 'open-account',
styleUrls: stylesArr,
templateUrl: './open-account.component.html',
})
和
var stylesArr = ['./open-account.component.scss'];
if (window.location.href.indexOf('widget=true') > -1) stylesArr.push('./open-account-widget-styles.component.scss');
@Component({
selector: 'open-account',
styleUrls: stylesArr,
templateUrl: './open-account.component.html',
})
和
@Component({
selector: 'open-account',
styleUrls: ['open-account.component.scss', 'open-account-widget-styles.component.scss'].filter(elem => {
if (elem === 'open-account.component.scss') return true;
if (elem === 'open-account-widget-styles.component.scss' && window.location.href.indexOf('widget=true') > -1) return true;
}),
templateUrl: './open-account.component.html',
})
,并在我的HTML的顶部:
<style type="text/css" *ngIf="false">
(the 'false' would be a variable, but putting in false doesnt even stop the style from loading)
...
</style>
我能做些什么来有条件地负载像这样的其他样式表?我不知道还有什么要尝试。
所以,你想,如果你加载部件一个部件使用不同的CSS? 你是如何构建你的应用程序?你在使用AOT吗? –
@SanderElias准确地说,我想加载一个额外的表格,如果我将组件加载为一个小部件,并且我在AOT – georgej
@SanderElias中构建,许多这些方法在将构建切换到AOT之前用于工作,现在没有他们工作 – georgej