Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular 4 : How to update an array bind to [mention] after an api call #41

Closed
ahmedbutt2015 opened this issue Sep 24, 2017 · 3 comments
Closed

Comments

@ahmedbutt2015
Copy link

ts file :
  ngOnInit():void {
    this.items.push("temp Name")
    let __this = this
    this._userService.getAll(1).subscribe(res => {
      res.users.forEach(function (a,b) {
        __this.items.push(a)
      })
      console.log(__this.items)
    })
  }

.html file :

<input type="text" [mention]="items" >

The array is been updated and have the data from api but the directive [mention] is bind to the old array contain values that been initialized statically at start !

@dmacfarlane
Copy link
Owner

Try the latest version just published.

@ahmedbutt2015
Copy link
Author

I'm using "angular2-mentions": "^0.7.0" latest but not working !

@dmacfarlane
Copy link
Owner

You will need to assign items to a new array for the change to be detected. For example:

      let newItems = [];
      res.users.forEach(function (a,b) {
        newItems.push(a);
      })
      __this.items = __this.items.concat(newItems);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants