[英]kendo grid odd behaviour around service instantiation
我在 Angular 模板中使用 Kendo Grid 并尝试允许组件中的服务定义一些 css 样式但遇到问题。
<kendo-grid
*ngIf="canLoad()"
[data]=etc...
[rowClass] = "rowCallback"
>
public canLoad() : boolean
{
return this.myservice !== undefined;
}
public rowCallback(context: RowClassArgs)
{
this.myservice.doSomething();
}
我收到错误消息“无法读取未定义的属性(读取‘doSomething’)” ...为什么当 ngIf 检查已将 myservice 评估为已实例化时我会收到错误消息? 如何让 rowCallback 等待服务实例化?
在上面的例子this.myservice.doSomething()
this
没有指向组件 class object,所以 myservice 是未定义的。
要解决此问题,您可以
rowClass
时将其绑定this
方法<kendo-grid
*ngIf="canLoad()"
[data]=etc...
[rowClass] = "rowCallback.bind(this)"
>
rowCallback
public rowCallback = (context: RowClassArgs) => {
this.myservice.doSomething();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.