我初學AngularJS角服務注入是不相符的
我有一個角度的服務如下
angular.module('TestModule', []).service('testservice', ['$timeout', testservice]);
function testservice($timeout) {
/* my function */
}
我在app.js
注入我的主要模塊,在該模塊中,如下angular.module("MainModule", ['TestModule']);
,並試圖注入TestService的在我的控制器如下
(function() {
'use strict';
angular
.module('MainModule')
.controller('testController', ['$scope', '$state', 'testservice', testController]);
function testController($scope, $state, testservice) {
/*I have my functions here */
}
})();
有時,它被成功注入和有時它拋出如下錯誤
未知提供商:testserviceProvider < - TestService的< - 的TestController
我無法猜測出了問題,我完全被卡住它。我做錯了什麼?
我不明白你發佈的代碼有多可能。請提供可以複製此錯誤的plunk或小提琴。 – estus
實際上,這個簡單的事情是按預期工作的,但是如果我在大型應用程序中合併相同類型的事物,它並不一致 –
它可能與$ timeout中的某些承諾沒有正確處理有關。 – neptune