-1

I keep getting this error: ERROR TypeError: Cannot read property 'name' of undefined. All I want to do is submit to next page if input is not empty. I am currently working with Clarity Vmware and Angular 5.0.5 My html looks something like this:

 <form #loginForm="ngForm" (ngSubmit)="onSubmit">
 <label for="name"> Text </label>
 <input type="text" class="form-control" id="name" required 
 [(ngModel)]="model.name" name="name" #name="ngModel"> 


 <button type="button" class="btn btn-primary" 
 [disabled]="loginForm.form.invalid"> Submit </button>

 </form>

And my function in typescript :

submitted = false;
onSubmit() {
if(this.submitted = true) {
this.router.navigate(['nextPage']); } }
constructor(private router: Router) {}

I looked through similas questions but none of them could answer my question. Why am I getting the error above and how can I make it successfully navigate to next page IF input not empty? Thank you in advanced

1
  • From ngModel line remove #name Commented Feb 20, 2018 at 11:24

1 Answer 1

0

Check if model is defined in your typescript code. Please upload error message screenshot

Sign up to request clarification or add additional context in comments.

1 Comment

That was the problem, I had forgotten to define the model! Thank you

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.