【发布时间】:2016-05-13 08:15:03
【问题描述】:
我在 typescript 中有这个组件定义:
import {Component, ViewEncapsulation} from 'angular2/core';
@Component({
selector: 'my-app',
templateUrl: '/views/sandbox.html',
styleUrls: ['/styles/sandbox.css'],
styles: [`.wow { background-color: red; }`],
encapsulation: ViewEncapsulation.Emulated
})
export class SandBox { }
根据这篇文章:http://blog.thoughtram.io/angular/2015/06/25/styling-angular-2-components.html 样式部分和外部样式表中的样式都应按角度内联到标题中。
不幸的是,第二个没有被注入,角度只注入了样式部分中的一个。
我试过从浏览器访问/styles/sandbox.css,没问题。 Angular 也能够访问 /views/sandbox.html,所以我不知道为什么它没有发生。
我正在使用:“angular2”:“2.0.0-beta.2”(最新测试版 AFAIK)
【问题讨论】:
-
删除 styleUrls 属性时是否注入?
-
总是注入“样式”。另一个不是。
-
你不能把你的绝对 URL 中的第一个斜杠去掉,让它看起来像这样
styles/sandbox.css吗?这对我有用。
标签: css angular angular2-template