从Angular2中的子元素中读取CSS类

时间:2017-10-06 08:45:13

标签: angular

有没有比使用nativeElement引用更聪明的方法来检索模板组件类:

this.classes= elm.nativeElement.getAttribute('class');

哪个会以字符串形式返回类列表,但我相信有更聪明的方法可以做到这一点......

背景: 我正在尝试在不使用CSS的情况下基于type类设置input type="password" ng-pristine属性。所以它基本上是基于textpasswordng-pristine之间切换。

1 个答案:

答案 0 :(得分:1)

这可以做你想要的:

<input #inp="ngForm" [type]="inp.pristine ? 'text' : 'phone'">