'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',[]);
现在我不明白我可以访问在另一个模块上定义的服务状态如何?
'use strict'; Feed .controller('FeedController',['$scope','$http','Status']);
我不应该对吗?但不知何故我是…还是正确的行为?
Module是在引导过程中应用于应用程序的配置和运行块的集合。模块可以列出其他模块作为依赖关系。根据模块意味着在需要模块加载之前需要加载所需的模块。
var myModule = angular.module('myModule',['module1','module2']);
当您注入模块时,服务在配置阶段已注册,您可以访问它们,因此要做一个很长的故事,这是Angular中依赖注入的正确行为和核心基础。
例如
angular.module('module1').service('appservice',function(appservice) { var serviceCall = $http.post('api/getUser()',"Role"); });
那么如何使用angular.module(‘mymodule’)来访问它;
angular.module('mymodule').controller('appservices',function(appservice) { var Servicedata= appservice.ServiceCall('role'); }
这怎么可以访问。如果有人有另一个建议,请说。