【发布时间】:2018-01-26 21:11:30
【问题描述】:
我有以下标签:
<tag-input hideForm="true" [onRemoving]="onRemoving"></tag-input>
[onRemoving]="onRemoving" 所在的函数被尝试删除值调用。
看起来像:
public onRemoving(tag: any): Observable<any> {
let del = '';
this.translate.get('confirmation_text').subscribe((res: string) => {
del = res['confirmation_text'];
});
}
问题出在这段代码中:
this.translate.get('confirmation_text').subscribe()...
我收到一个错误:
TypeError: 无法读取未定义的属性“get”
我认为原因在于 this 上下文的可见性区域
构造函数:
constructor(private translate: TranslateService) {
}
【问题讨论】:
-
你能添加你的构造函数,依赖注入应该发生在哪里吗?
-
是的,再看一遍
-
我想我无法访问类的全局
this,它只适用于tag-input的本地this; -
显示
this.translate.get -
在构造函数中写入以下
this.onRemoving = this.onRemoving.bind(this)
标签: angular