我有一个角应用,定义了一些全局值如下:我需要做什么来访问控制器中的全局数据?
angular.module('ionicApp', ['ionic', 'ngCordova', 'services'])
.value('GlobalValues',
{
host : "http://localhost/",
accountApi: 'MyService/api/AccountApi/'
// ... other stuff like this
})
.run(function ($ionicPlatform) {
// etc..
})
我能够访问GlobalValues
在我UserService
,其定义为:
angular.module('services', [])
.service('UserService', function($q, $http, $ionicLoading, GlobalValues) {
alert(GlobalValues.host); // has a value
});
但在我CreateAdController
,GlobalValues
未定义:
(function() {
'use strict';
angular.module('ionicApp')
.controller('CreateAdController', ['$cordovaCamera', 'Camera', '$scope', '$http', 'GlobalValues', CreateAdController]);
function CreateAdController($cordovaCamera, $scope, $http, GlobalValues) {
alert(GlobalValues.host); // is undefined!
};
})();
什么我需要做的ACCES来自我的CreateAdController
的GlobalValues
的数据?
注射问题。 GlobalValues是第五参数,但您只向控制器注入4个参数... –
您插入的模块顺序和发送模块的函数不正确。根据上面的代码,GlobalValues将包含$ http对象。 –
@PoyrazYilmaz是对的:) –