javascript - does a directive need to list the service? -
i know there few ways format but, if new service injected controller:
analyticscontroller.$inject = ['$scope', 'analyticsservice', 'nvd3', 'gridster'];
does service still need in directive in angular 1.5?
import { analyticscontroller } './analytics.controller'; export class analyticscomponent { constructor(){ this.bindings = { chartdata: '<' }; this.controller = analyticscontroller; this.controlleras = 'vm'; this.templateurl = 'analytics/analytics.html'; //maybe service? } }
after injecting service use constructor expose class service.
analyticscomponent.$inject = ['$scope', 'analyticsservice', 'nvd3', 'gridster']; export class analyticscomponent { constructor($scope, analyticsservice, nvd3, gridster) { this.bindings = { chartdata: '<' }; this.controller = analyticscontroller; this.controlleras = 'vm'; this.templateurl = 'analytics/analytics.html'; this.analyticsservice = analyticsservice; } setanalytics(data) { this.analyticsservice.methodname(data); } }
Comments
Post a Comment