2016-09-19 5 views
0

Я не могу позвонить из этой службы из этой директивы. Я использую шаблон с помощью wizard.js для создания модальной формы мастера. Я не уверен, что это проблема с угловым 2.Как я могу позвонить службе из директивы в Angular 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(); 
      } 
} 

Любые идеи?

ответ

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(); 
      } 
}