2017-01-24 16 views
1

我有一个角2应用程序,并希望把我的部件之一到iframe窗口小部件时查询字符串widget=true存在。当这个字符串出现时,我想将一个额外的样式表加载到该组件中以稍微改变窗口小部件视图。这可能吗?我将如何做到这一点?角2 - 如果存在查询字符串,加载另一个样式表

只是为了澄清:

我有我作为一个正常的网页使用,但希望能够把它作为一个iframe控件太组件。当查询字符串widget=true存在时,我会知道该页面在iframe中。在这种情况下,我想一个额外的样式表加载到组件

+0

没有得到你想要的。你想把一个组件变成iframe,或者你想加载另一种风格? – smnbbrv

+1

我有一个组件用作常规页面,但也希望能够将它作为iframe小部件。当查询字符串'widget = true'出现时,我会知道该页面在iframe中。在这种情况下,我想装载更多的样式到组件 – georgej

回答

2

那么有几种方法。

首先,显而易见的是,在<style>标签中包含样式,*ngIf在URL中检查此参数。

其次,我找到更好的,是setting the style into styleUrls component meta property

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 { 
/* . . . */ 
} 
+0

我没有任何运气* ngIf的''