【发布时间】:2018-07-31 13:57:01
【问题描述】:
我的 Angular 项目中的组件样式存在问题。我基本上无法让它工作。为了解释我的问题,我使用 Angular CLI(CLI 6.0.8,angular 6.1.0)创建了一个新项目。我马上创建了一个新的测试组件,我在其中声明了以下内容:
- - - - - - - - - - - - -
COMPONENT TEMPLATE FILE:
- - - - - - - - - - - - -
<div>with div</div>
without div
- - - - - - - - - - - - -
COMPONENT STYLE FILE:
- - - - - - - - - - - - -
:host
{
background-color: blue;
}
(打字稿声明文件没有变化)
我将这个组件包含在应用模板中,并在 app.css 文件中为其声明了一些样式:
- - - - - - - - - - - - -
APP TEMPLATE FILE:
- - - - - - - - - - - - -
<app-test class='test'></app-test>
- - - - - - - - - - - - -
APP STYLE FILE:
- - - - - - - - - - - - -
.test
{
background-color: red;
width: 350px;
}
这是我得到的结果:
IMAGE : style does not apply correctly (background color applies to the free text only)
IMAGE : usually element sizes are highlighted in blue when shown
如图所示,样式未正确应用,无论是在父作用域还是在组件作用域中定义(使用 :host)。样式已更新但未显示。当我在浏览器中将“app-test”标签更改为“div”标签时(使用调试工具> 编辑为 HTML),它会正确显示:
IMAGE : changing the angular component tag into a div tag sorts the issue
我认为这与角度显示组件的方式有关,因为将标签更改为 DIV 有效。但我不明白这个问题来自哪里。此问题出现在使用 CLI 新建的项目上,项目配置中没有任何配置...
谁能帮帮我?
【问题讨论】:
标签: angular