Sri*_*kar 2 ng2-smart-table angular
我在我的组件中使用ng2-smart-table.
我试图调用父组件的approveTheOrder()方法,但我无法获取父类的对象
以下是片段
{
title: "Actions",
type: "custom",
renderComponent: ActionRenderComponent,
onComponentInitFunction(instance) {
instance.actionEmitter.subscribe(row => {
if(row == CONSTANT.STATUS_APPROVE){
//here 'row' value is from childComponent-ActionRenderComponent,which I am able to get easily in parentComponet
this.approveTheOrder(instance.rowData.id); // here this is undefined,
}
if(row == CONSTANT.STATUS_REJECT){
this.rejectOrder();//this is undefined
}
if(row == CONSTANT.STATUS_PENDING){
this.pendingOrder(); // this is undefined
}
});
},
filter: false
};
Run Code Online (Sandbox Code Playgroud)
有没有人知道如何在下面的onComponentInitFunction()中获得'this'?
此外,我试图使用'绑定'功能未能成功实现目标,任何人都可以在这里指导我,我真的卡在这一点.
编辑1 请注意,我能够从中获取事件ChildComponent在为父级,但这里的问题是特定于NG2智能表的组成部分.
要从ChildComponent获取值,我正在尝试使用ng2-smart-table组件的onComponentInitFunction(instance)的内置回调函数
以下语法:
{
onComponentInitFunction(instance) {
...
Run Code Online (Sandbox Code Playgroud)
将被转换为函数表达式:
{
onComponentInitFunction: function(instance) {
...
Run Code Online (Sandbox Code Playgroud)
您应该使用箭头功能来保留this:
onComponentInitFunction: (instance) => {
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2492 次 |
| 最近记录: |