Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度2-如果存在查询字符串,则加载另一个样式表_Angular_Widget_Stylesheet - Fatal编程技术网

Angular 角度2-如果存在查询字符串,则加载另一个样式表

Angular 角度2-如果存在查询字符串,则加载另一个样式表,angular,widget,stylesheet,Angular,Widget,Stylesheet,我有一个Angular 2应用程序,当出现查询字符串widget=true时,我想将我的一个组件转换为iframe小部件。当这个字符串出现时,我想在组件中加载一个额外的样式表来稍微更改小部件视图。这可能吗?我该怎么做 我想澄清一下: 我有一个作为常规页面使用的组件,但也希望能够将其作为iframe小部件使用。当查询字符串widget=true出现时,我将知道页面位于iframe中。在这种情况下,我想向组件加载一个额外的样式表 首先,显然是肮脏的,包括样式作为标记,带有*ngIf在URL中检查此参

我有一个Angular 2应用程序,当出现查询字符串
widget=true
时,我想将我的一个组件转换为iframe小部件。当这个字符串出现时,我想在组件中加载一个额外的样式表来稍微更改小部件视图。这可能吗?我该怎么做

我想澄清一下:


我有一个作为常规页面使用的组件,但也希望能够将其作为iframe小部件使用。当查询字符串
widget=true
出现时,我将知道页面位于iframe中。在这种情况下,我想向组件加载一个额外的样式表

首先,显然是肮脏的,包括样式作为
标记,带有
*ngIf
在URL中检查此参数

第二,我发现更好的是:

let-styleurl=[];
if(window.location.href.contains('widget=true')){
push('/path/to/style');
}
@组成部分({
选择器:“英雄应用程序”,
模板:`
英雄之旅
`,
样式栏:
})
导出类组件{
/* . . . */
}

没有得到你想要的。您想将一个组件转换为iframe还是想加载另一种样式?我有一个组件,可以用作常规页面,但也希望能够将其用作iframe小部件。当查询字符串
widget=true
出现时,我将知道页面位于iframe中。在本例中,我想向组件加载一个额外的样式表。我在
标记上没有使用*ngIf的运气,但是您的第二种方法非常有效
let styleUrls = [];

if (window.location.href.contains('widget=true')) {
  styleUrls.push('/path/to/style');
}

@Component({
  selector: 'hero-app',
  template: `
    <h1>Tour of Heroes</h1>
    <hero-app-main [hero]=hero></hero-app-main>`,
  stylesUrls: 
})
export class HeroAppComponent {
/* . . . */
}