Tomas
Tomas

Reputation: 3436

Read CSS classes from child element in Angular2

Is there a more clever way of retrieving template component classes than using nativeElement reference:

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

Which will return list of classes in string form, but I believe there is much more clever way of doing that...

Background: I'm trying to set type property of input type="password" basing on ng-pristine class without using CSS. So it's basically toggling between text and password basing on ng-pristine.

Upvotes: 0

Views: 66

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657338

This could do what you want:

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

Upvotes: 1

Related Questions