4

我正在学习 Angular 2,我想知道是否可以通过使用这样的组件选择器来应用 css 样式:

组件

@Component({
    selector: 'app',
    styleUrl: './local.css',
    templateUrl: './app.html',
})
export class AppComponent { }  

样式

app {
    width: 10px;
    height: 100px;
    background-color: red;
}

假设这是可能的,这是最好的方法吗?

4

1 回答 1

9

:host改为使用

:host {
    width: 10px;
    height: 100px;
    background-color: red;
}

app当您想从组件外部应用样式时使用。

于 2016-10-18T07:49:39.067 回答