我需要一些组件选择器的帮助。 我尝试添加类.Home_root像这样:
@Component({
selector: '.Home_root',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss']
})
但是我在浏览器中看到的渲染是:
<div class="home_root ng-star-inserted" _nghost-c1="">...</div>
所以,我的类名是小写的。
有什么方法可以保留类名,就像我写它的方式一样?是什么原因导致这种转换? 我试图在网上找到一些答案,但没有运气。
我的角度代码版本是5.2.0
如果我没有提供足够的代码来定位问题的原因,我提前道歉。由于我仍然不熟悉角度,我什至不知道我应该发布代码的哪一部分。
选择器是 HTML 文件中组件的名称,您不能这样做。
正确的方式。
@Component({
selector: 'home-root',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss']
})
您的 HTML 将呈现此内容。
<home-root></home-root>
如果你想改变你的样式根选择器,你可以在你的CSS文件中这样做。
:host {
//your style here will be applied to the root selector.
}