2017-03-20 13 views
1

typescriptでalertifyプラグインを使用していて、getData関数を認識できません。以下のコードを参照してくださいtypescriptの呼び出し関数がalertify.jsで機能していません

copyTemplate(id:any, pluginId:any, name:any) { 
    alertify.confirm(`Are you sure you want to copy ${name} to a new project template?`, function() { 
     this.getData(); 
    }, function() { 
      (<HTMLInputElement>document.getElementById('prefGroup')).value = '0'; 
    }); 
} 

何が問題なのですか?ブラウザのエラー:

core.umd.js:3064 EXCEPTION: this.getData is not a functionErrorHandler.handleError @ core.umd.js:3064next @ core.umd.js:8039schedulerFn @ core.umd.js:3689SafeSubscriber.__tryOrUnsub @ Subscriber.ts:238SafeSubscriber.next @ Subscriber.ts:190Subscriber._next @ Subscriber.ts:135Subscriber.next @ Subscriber.ts:95Subject.next @ Subject.ts:61EventEmitter.emit @ core.umd.js:3675NgZone.triggerError @ core.umd.js:4038onHandleError @ core.umd.js:3999ZoneDelegate.handleError @ zone.js?1489977130473:207Zone.runTask @ zone.js?1489977130473:139ZoneTask.invoke @ zone.js?1489977130473:304 core.umd.js:3069 ORIGINAL STACKTRACE:ErrorHandler.handleError @ core.umd.js:3069next @ core.umd.js:8039schedulerFn @ core.umd.js:3689SafeSubscriber.__tryOrUnsub @ Subscriber.ts:238SafeSubscriber.next @ Subscriber.ts:190Subscriber._next @ Subscriber.ts:135Subscriber.next @ Subscriber.ts:95Subject.next @ Subject.ts:61EventEmitter.emit @ core.umd.js:3675NgZone.triggerError @ core.umd.js:4038onHandleError @ core.umd.js:3999ZoneDelegate.handleError @ zone.js?1489977130473:207Zone.runTask @ zone.js?1489977130473:139ZoneTask.invoke @ zone.js?1489977130473:304 core.umd.js:3070 TypeError: this.getData is not a function at Object.eval [as onOkay] (project-templates.component.ts:126) at HTMLButtonElement. (alertify.js?1489977130519:280) at ZoneDelegate.invokeTask (zone.js?1489977130473:236) at Object.onInvokeTask (core.umd.js:3969) at ZoneDelegate.invokeTask (zone.js?1489977130473:235) at Zone.runTask (zone.js?1489977130473:136) at HTMLButtonElement.ZoneTask.invoke (zone.js?1489977130473:304)ErrorHandler.handleError @ core.umd.js:3070next @ core.umd.js:8039schedulerFn @ core.umd.js:3689SafeSubscriber.__tryOrUnsub @ Subscriber.ts:238SafeSubscriber.next @ Subscriber.ts:190Subscriber._next @ Subscriber.ts:135Subscriber.next @ Subscriber.ts:95Subject.next @ Subject.ts:61EventEmitter.emit @ core.umd.js:3675NgZone.triggerError @ core.umd.js:4038onHandleError @ core.umd.js:3999ZoneDelegate.handleError @ zone.js?1489977130473:207Zone.runTask @ zone.js?1489977130473:139ZoneTask.invoke @ zone.js?1489977130473:304 Subscriber.ts:241 Uncaught TypeError: this.getData is not a function

答えて

2

矢印機能を使用してください。範囲は、「この」コールバック

copyTemplate(id:any, pluginId:any, name:any) { 
alertify.confirm('Are you sure you want to copy ${name} to a new project template?', () => { 
    this.getData(); 
},() => { 
     (<HTMLInputElement>document.getElementById('prefGroup')).value = '0'; 
}); 

}

または関数の外にこの値を格納し、それが

copyTemplate(id:any, pluginId:any, name:any) { 
let self = this; 
alertify.confirm('Are you sure you want to copy ${name} to a new project template?', function() { 
    self.getData(); 
}, function() { 
     (<HTMLInputElement>document.getElementById('prefGroup')).value = '0'; 
}); 

}

+0

はあなたにサーありがとうござい使用内部違います! !それは働く!!!!! –

関連する問題