0

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.

3
  • Sounds like a bad idea if this Angular 2 or later. The element provides such a status. angular.io/api/forms/AbstractControl#pristine Commented Oct 6, 2017 at 8:50
  • You can try <input #inp="ngForm" [type]="inp.pristine ? 'text' : 'phone'">, but no guarantees this will do anything useful. Commented Oct 6, 2017 at 8:54
  • 1
    @Günter Zöchbauer I choose to read dirty property of FormControl. Works fine. If no further solutions will pop out I'' post it as answer Commented Oct 6, 2017 at 11:57

1 Answer 1

1

This could do what you want:

<input #inp="ngForm" [type]="inp.pristine ? 'text' : 'phone'">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.