有没有比使用nativeElement
引用更聪明的方法来检索模板组件类:
this.classes= elm.nativeElement.getAttribute('class');
哪个会以字符串形式返回类列表,但我相信有更聪明的方法可以做到这一点......
背景:
我正在尝试在不使用CSS的情况下基于type
类设置input type="password"
ng-pristine
属性。所以它基本上是基于text
在password
和ng-pristine
之间切换。
答案 0 :(得分:1)
这可以做你想要的:
<input #inp="ngForm" [type]="inp.pristine ? 'text' : 'phone'">