gpt4 book ai didi

javascript - 指令是否需要列出服务?

转载 作者:行者123 更新时间:2023-12-03 06:09:50 24 4
gpt4 key购买 nike

我知道有几种方法可以格式化它,但是,如果将新服务注入(inject) Controller :

AnalyticsController.$inject = ['$scope', 'analyticsService', 'nvd3', 'gridster'];

Angular 1.5 中的服务还需要包含在指令中吗?

import { AnalyticsController } from './analytics.controller';

export class AnalyticsComponent {

constructor(){
this.bindings = {
chartData: '<'
};
this.controller = AnalyticsController;
this.controllerAs = 'vm';
this.templateUrl = 'analytics/analytics.html';
//Maybe service?
}
}

最佳答案

注入(inject)服务后,使用构造函数将您的类公开给服务。

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

关于javascript - 指令是否需要列出服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39374814/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com