1
我有两个AngularJs模块,一个是我的应用程序,另一个是常量列表。我想将常量模块注入到我的应用程序模块中,并使用控制器中的常量。我已经能够在工厂内实现这个功能,但是我无法访问我的控制器中的常量。将模块注入控制器AngularJs
应用模块:
(function() {
'use strict';
angular.module('myapp', [
'constants',
'ngMaterial',
'ngCordova',
'ngStorage',
'relativeDate',
'ui.router',
'myapp.services.myservice'
])
恒模:
angular.module('constants', [])
.constant('appName', 'mynewapp');
在我的工厂在那里我可以访问我的常量:
(function() {
'use strict';
angular.module('myapp.services.myservice', [])
.factory('Myservice', function ($http, appName) {
console.log(appName); //works great!
我的控制,我不能访问常量
(function() {
'use strict';
angular.module('myapp')
.controller('MyController', [
'$cordovaOauth',
'$state',
'$rootScope',
'Myservice',
MyController
]);
function MyController($cordovaOauth, $state, $rootScope, Myservice, appName) {
console.log(appName); //undefined
YES!谢谢! – tester123
不要忘记批准好的答案,特别是当它明显是正确的答案时,其他人不能作出更好的答案。 – AdamCooper86
等待时间限制接受... – tester123