'use strict';
var trkiApp = angular.module('trkiApp', [
'trkiApp.tStatus',
'trkiApp.feed'
]);
var tStatus = angular.module('trkiApp.tStatus', [])
.factory('Status', ['$q']);
var feed = angular.module('trkiApp.feed', []);
Run Code Online (Sandbox Code Playgroud)
现在我不明白我怎么可能访问在另一个模块上定义的服务状态?
'use strict';
feed
.controller('FeedController', ['$scope','$http','Status']);
Run Code Online (Sandbox Code Playgroud)
我不应该对吗?但不知怎的,我......或者这是一个正确的行为?
Ale*_*hin 52
甲模块在配置和运行块的集合,其获得在引导过程中施加到该应用程序.模块可以列出其他模块作为其依赖项.根据模块的不同,需要在加载需求模块之前加载所需的模块.
var myModule = angular.module('myModule', ['module1','module2']);
Run Code Online (Sandbox Code Playgroud)
当你注入你的模块时,服务在配置阶段就已经注册了,你可以访问它们,所以长话短说,这是正确的行为和Angular中依赖注入的核心基础.例如
angular.module('module1').service('appservice', function(appservice) {
var serviceCall = $http.post('api/getUser()',"Role");
});
Run Code Online (Sandbox Code Playgroud)
那么如何使用它来访问它 angular.module('myModule');
angular.module('myModule').controller('appservice', function(appservice)
{
var Servicedata= appservice.ServiceCall('role');
}
Run Code Online (Sandbox Code Playgroud)
这是如何访问它的.如果有人有其他建议请说出来.