1
votes

Two-way Data binding using ngModel is not working in tag-inputs. Can one please help.

https://stackblitz.com/edit/angular-9muqcy?file=src%2Fapp%2Fapp.component.html

3
It works fine the array is updatedManos Kounelakis
Where, no i checked using console. It gives undefinedSiva Goud
what is the error ?Sarthak Aggarwal
what i am updating in tag-input that i want to show in console. But it gives undefined.Siva Goud
You console log this.hiManos Kounelakis

3 Answers

0
votes

Just change this:

hai(){
console.log(this.hi)
}

to this:

hai(){
console.log(this.Myarray)
}

Check this link: https://stackblitz.com/edit/angular-czsxvq

0
votes

you are trying to show hi while your ngModel variable is Myarray

0
votes

New Edit -

hai(){
   let currItem = this.Myarray[this.Myarray.length-1]['value'];
   this.Myarray.splice(this.Myarray.length-1);
   this.Myarray.push(currItem);
   console.log(this.Myarray)
  }

You're getting this error because 'hi' is not defined, it's just declared. This post is a good explanation.

What's the difference between variable definition and declaration in JavaScript?

You need to edit your hai function.

hai(){ console.log(this.Myarray) }

Also add this

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

@NgModule({
  imports:      [ BrowserModule, FormsModule, TagInputModule,BrowserAnimationsModule ],