我建立了下一个控制器:
.controller('myCtrl', function($scope, $route, $routeParams, $location)
现在我想注入一种叫做SharedState的东西。试着:
.controller('chatCtrl' ['SharedState', function($scope, $route, $routeParams, $location, SharedState)
要么:
.controller('chatCtrl' ['$scope','SharedState', '$route', '$routeParams', '$location', function($scope, SharedState, $route, $routeParams, $location)
都返回错误:
Error: [ng:areq] http://errors.angularjs.org/1.2.27/ng/areq?p0=myCtrl&p1=not%20aNaNunction%2C%20got%20undefined
注射的正确方法是什么?
最佳答案
我的第二次尝试:.controller('chatCtrl', ['$scope','SharedState', '$route', '$routeParams', '$location', function($scope, SharedState, $route, $routeParams, $location)
与逗号作品。
感谢您的帮助! @Aprillion
关于javascript - Angular js Controller 多次注入(inject),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27536726/