0

I have a following tag:

<tag-input hideForm="true" [onRemoving]="onRemoving"></tag-input>

Where [onRemoving]="onRemoving" is function is called by attempts to delete value.

It looks like:

public onRemoving(tag: any): Observable<any> {

    let del = '';

    this.translate.get('confirmation_text').subscribe((res: string) => {
      del = res['confirmation_text'];
    });
}

Problem is in this code:

this.translate.get('confirmation_text').subscribe()...

I get an error:

TypeError: Cannot read property 'get' of undefined

I think cause is in area of visibility of this context

Constructor:

constructor(private translate: TranslateService) {
}
16
  • Can you add your constructor, where the dependency injection should happen? Commented Jan 26, 2018 at 10:33
  • Yes, look again Commented Jan 26, 2018 at 10:34
  • I think I can not get access to global this of class, it works only with local this of tag-input; Commented Jan 26, 2018 at 10:35
  • show the this.translate.get Commented Jan 26, 2018 at 10:36
  • 1
    Write in constructor the following this.onRemoving = this.onRemoving.bind(this) Commented Jan 26, 2018 at 11:00

1 Answer 1

3

change [onRemoving]="onRemoving" to (onRemoving)="onRemoving($event)"

It might be useful Angular2, ng2-tag-input prevent duplicate value on editable

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

8 Comments

And how to pass parameter to "onRemoving()"?
It does not work, it removes tags without confirmation in this case
May be (onRemoving)="onRemoving($event)"?
yes, you can use $event as param if you want to pass browser's event object
I tried, It does not work, it removes tags without confirmation in this case
|

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.