我无法通过此指令调用我的服务。我使用带有wizard.js的模板来制作向导模态表单。我不确定这是一个有角度的2问题顺便说一句。
这是我的指示:
import {Directive,Input, EventEmitter, ElementRef, Output} from '@angular/core';
import {Injectable,Inject} from '@angular/core';
import {Service} from '../../../service/service';
@Directive ({
selector: '[bootstrap-application-wizard]',
providers:[DashboardService]
})
export class BootstrapApplicationWizard {
$el: any;
constructor(
private _service:Service){}
function render(){
wizard.on('submit', function(wizard): void {
this.submit = {'data1': 'John','data2': 'Doe'};
this._service.postData('data',this.submit).subscribe(x=>{
console.log('ok');
});
}
ngOnInit(){
this.render();
}
}
有什么想法吗?
答案 0 :(得分:1)
删除function
并将function ()
替换为() =>
@Directive ({
selector: '[bootstrap-application-wizard]',
providers:[DashboardService]
})
export class BootstrapApplicationWizard {
$el: any;
constructor(private _service:Service){}
render(){
wizard.on('submit', (wizard): void => {
this.submit = {'data1': 'John','data2': 'Doe'};
this._service.postData('data',this.submit).subscribe(x=>{
console.log('ok');
});
}
ngOnInit(){
this.render();
}
}