[英]How can i call a service from a directive in Angular 2
我无法从该指令调用服务。 我将模板与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();
}
}
有任何想法吗 ?
删除function
并用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();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.