1

Using the Angular 2 Validators, if the form is invalid, the form button is disabled from the HTML itself like so:

<button class="btn btn-info" [disabled]="!signupForm.valid">Sign Up</button>

How would I use this same effect in the appropriate TS? For instance:

youshallnotpass(){ !this.signupForm.valid; }

1 Answer 1

1

If you are using template driven forms, you could get a hold of the it using ViewChild. Here's something you can do:

Considering:

<form ... #myForm="ngForm">

You could, at the TypeScript component code:

import { ViewChild, NgForm } from '@angular/core';
...
export class MyFormComponent {
    ...
    @ViewChild('myForm') public myForm: NgForm;

    youshallnotpass(){ return !this.myForm || !this.myForm.valid; }
    ...
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.