【发布时间】:2016-10-20 09:24:06
【问题描述】:
我正在尝试学习Angular2,但是我对组件样式有点困惑,在组件装饰器中我们可以指定将它们应用到我们的组件的样式,有两种方法可以做到这一点:
1- 我们可以在 styleUrls 属性中指定 css 文件,它是一个字符串数组,这对我来说是逻辑,因为我们可能有多个 css 文件
@Component({
selector: 'users-list',
templateUrl: 'app/users-list.template.html',
styleUrls: ['style1.css', 'style2.css']
})
2- 我们可以在 styles 属性中编写我们的样式,它也是一个字符串数组,这就是我感到困惑的地方!我的意思是为什么样式属性是一个字符串数组?为什么它不仅仅是一个字符串!
@Component({
selector: 'users-list',
templateUrl: 'app/users-list.template.html',
styles: [
`
.glyphicon{
cursor: pointer;
}
`
]
})
在 Angular2 的官方文档中,他们没有说明为什么要在其中放置一个字符串数组而不是一个字符串!谁能解释一下!!
【问题讨论】:
-
实际上他们将其视为一个 json 字符串,并从中选择类,然后将行为应用到该类