AngularJS access service from different module

后端 未结 3 1637
我在风中等你
我在风中等你 2020-12-14 07:13
\'use strict\';

var trkiApp = angular.module(\'trkiApp\', [ 
  \'trkiApp.tStatus\', 
  \'trkiApp.feed\'
]);



var tStatus = angular.module(\'trkiApp.tStatus\', [])         


        
3条回答
  •  南方客
    南方客 (楼主)
    2020-12-14 07:36

    I had a similar issue when trying to inject dependencies from another module. Alex's answer didn't work for me. I was getting a circular dependencies error.

    To fix it, make sure you are including all the module-specific JavaScript before. For example moduleA was defined in another JS file.

    var app = angular.module('plunker', ['moduleA']);
    
    app.controller('MainCtrl', function($scope, MainService) {
      $scope.name = 'World';
    
      $scope.hello = MainService.hello();
    
    });
    

    Working example Plunker

提交回复
热议问题