我有一个角度应用,定义如下,带有一些全局值:
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!
};
})();
从我的GlobalValues
访问CreateAdController
中的数据需要做什么?
答案 0 :(得分:0)
(function() {
'use strict';
angular.module('ionicApp')
.controller('CreateAdController', ['$cordovaCamera', 'Camera', '$scope', '$http', 'GlobalValues']);
function CreateAdController($cordovaCamera, Camera, $scope, $http, GlobalValues) {
alert(GlobalValues.host); // is undefined!
};
})();
以上应该有效我做了一些改动。另外,CreateAdController也不需要再次注入
答案 1 :(得分:0)
你搞砸了你的注射。注入语句中有一些值太多,或者方法签名中的值很少。
var welcome = "hello!"
let range = welcome.endIndex.advancedBy(-6)..<welcome.endIndex
welcome.removeRange(range)
//I get "" as result rather than "hello" where the exclamation mark is removed
确保遵守进样器/功能签名顺序。