【发布时间】:2016-07-13 11:10:15
【问题描述】:
我正在设置一个基本的 Angular 应用程序,并且我正在尝试在我的视图中注入一些 CSS。这是我的组件之一的示例:
import { Component } from 'angular2/core';
import { ROUTER_PROVIDERS, ROUTER_DIRECTIVES, RouteConfig } from 'angular2/router';
import { LandingComponent } from './landing.component';
import { PortfolioComponent } from './portfolio.component';
@Component({
selector: 'portfolio-app',
templateUrl: '/app/views/template.html',
styleUrls: ['../app/styles/template.css'],
directives: [ROUTER_DIRECTIVES],
providers: [ROUTER_PROVIDERS]
})
@RouteConfig([
{ path: '/landing', name: 'Landing', component: LandingComponent, useAsDefault: true },
{ path: '/portfolio', name: 'Portfolio', component: PortfolioComponent }
])
export class AppComponent { }
现在从我的服务器请求 .css 文件,当我检查页面源时,我可以看到它已添加到头部。但是发生了一些奇怪的事情:
<style>@media (min-width: 768px) {
.outer[_ngcontent-mav-3] {
display: table;
position: absolute;
height: 100%;
width: 100%;
}
.mainContainer[_ngcontent-mav-3] {
display: table-cell;
vertical-align: middle;
}
.appContainer[_ngcontent-mav-3] {
width: 95%;
border-radius: 50%;
}
.heightElement[_ngcontent-mav-3] {
height: 0;
padding-bottom: 100%;
}
}</style>
从此文件生成:
/* Small devices (tablets, 768px and up) */
@media (min-width: 768px) {
/* center the mainContainer */
.outer {
display: table;
position: absolute;
height: 100%;
width: 100%;
}
.mainContainer {
display: table-cell;
vertical-align: middle;
}
.appContainer {
width: 95%;
border-radius: 50%;
}
.heightElement {
height: 0;
padding-bottom: 100%;
}
}
谁能解释一下_ngcontent-mav标签的来源,它代表什么以及如何摆脱它?
我认为这就是我的样式没有应用于我的模板的原因。
如果您需要有关应用程序结构的更多信息,请查看我的gitRepo,或询问,我会将代码添加到问题中。
感谢您的帮助。
【问题讨论】:
-
默认封装为ViewEncapsulation#Emulated,查看一下。
标签: css typescript angular