Angular组件类选择器,案例未保留

时间:2018-06-15 14:25:13

标签: angular selector case-sensitive

我需要一些组件选择器的帮助。 我尝试像这样添加类.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

我提前道歉,如果我没有提供足够的代码来找出问题的原因。由于我还不熟悉角度,我甚至不知道我应该发布的代码部分。

1 个答案:

答案 0 :(得分:-2)

选择器是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.
}