【发布时间】:2016-01-13 12:19:48
【问题描述】:
我的 Angular 2 应用程序中有两个组件,它们在 SASS 文件中定义了不同的样式。不幸的是,这两个组件的样式似乎都在加载,导致 html 和 body 样式冲突。
我的组件定义如下所示:
@Component({
selector: 'signup',
directives: [RouterOutlet, RouterLink],
styles: [require('../sass/signup.scss').toString()],
template: require('./signup.component.html')
})
和
@Component({
selector: 'signin',
directives: [RouterOutlet, RouterLink],
styles: [require('../sass/signin.scss').toString()],
template: require('./signin.component.html')
})
样式表如下所示:
// signup.scss
html, body {
height:100%;
background-color: #eaeaea;
display: flex;
align-items: center;
justify-content: center;
display: -webkit-flex;
-webkit-align-items: center;
-webkit-justify-content: center;
}
和
// signin.scss
html, body {
height:100%;
background-color: #373746;
display: flex;
align-items: center;
justify-content: center;
display: -webkit-flex;
-webkit-align-items: center;
-webkit-justify-content: center;
}
两个组件的背景颜色都是#373746。
有什么想法吗?我可以轻松地创建两个单独的 <div>s 并带有 id 或类,但这将是一种解决方法;随着我的应用程序的增长,我真的不想跟踪为哪些组件定义了哪些样式。
【问题讨论】: