[英]Angular 8, how to reference a component property inside a function of a javascript library
I am using Semantic UI in angular and I have the following code:我在 angular 中使用语义 UI,我有以下代码:
componentProperty: boolean = false;
ngOnInit() {
(<any>$('.ui.dropdown')).dropdown();
(<any>$('.ui.input')).popup({
on: 'focus',
onShow: (e) => {
return this.componentProperty;
}
});
}
the function popup is defined by semantic UI.功能弹出是由语义 UI 定义的。 Semantic UI relies on Jquery.语义 UI 依赖于 Jquery。 Here componentProperty is undefined.这里的 componentProperty 是未定义的。
This about scope.这是关于范围的。 Try:尝试:
ngOnInit() {
const me = this;
(<any>$('.ui.dropdown')).dropdown();
(<any>$('.ui.input')).popup({
on: 'focus',
onShow: (e) => {
return me.componentProperty;
}
});
}
Have you tryed to define the onShow function in the components scope?您是否尝试过在组件范围内定义 onShow 函数?
ngOnInit() {
const onShow = () => this.componentProperty;
(<any>$('.ui.input')).popup({
on: 'focus',
onShow
});
}
And if that still won't work:如果这仍然不起作用:
const doOnShow = () => this.componentProperty;
(<any>$('.ui.input')).popup({
on: 'focus',
onShow: doOnShow.bind(this)
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.