我正面临angularjs的一个奇怪行为。
.factory('configService', function($http){
var base = 'http://Harold:Pituca521zkjOidksjdIIQUdjsdh120@localhost:3000/configuration/';
var getConfig = function(){
return $http.get(base + 'config');
};
var setConfig = function(config){
return $http.post(base + 'update', config);
};
return {
getConfig: getConfig,
setConfig: setConfig
};
})
.controller('ConfigurationController', function($scope, $http, $window, configService){
$scope.config = {};
configService.getConfig()
.success(function(data, status, headers, config){
console.log(data);
$scope.config = data;
});
$scope.saveConfiguration = function(config){
configService.getConfig(config)
.success(function(data, status, headers, config){
$window.location.reload();
});
};
});
当我做console.log(数据)时,我得到的是一个URL,而不是来自本地主机的从未命中的对象。
/Users/rodrigoqueirolo/Desktop/factory/public/index.html
我认为问题是因为带有凭据的URL,但令人惊讶的是,我有其他6条路由在做同样的事情(CRUD)。这是我点击输入表格时的完整错误。
TypeError: Cannot assign to read only property 'daily_cota_premium_user' of /Users/user/Desktop/factory/public/index.html
at Oa (file://localhost/Users/user/Desktop/final/admin/angular.min.js:102:253)
at Function.d.assign (file://localhost/Users/user/Desktop/final/admin/angular.min.js:104:22)
at O (file://localhost/Users/user/Desktop/final/admin/angular.min.js:210:465)
at $$writeModelToScope (file://localhost/Users/user/Desktop/final/admin/angular.min.js:215:271)
at file://localhost/Users/user/Desktop/final/admin/angular.min.js:215:209
at k (file://localhost/Users/user/Desktop/final/admin/angular.min.js:213:285)
at g (file://localhost/Users/user/Desktop/final/admin/angular.min.js:213:215)
at $$runValidators (file://localhost/Users/user/Desktop/final/admin/angular.min.js:213:499)
at $$parseAndValidate (file://localhost/Users/user/Desktop/fina/admin/angular.min.js:215:130)
at $commitViewValue (file://localhost/Users/user/Desktop/final/admin/angular.min.js:214:272)
感谢
我不是javascript专家,但我的看法是:
更改服务的返回以返回运行功能的函数(听起来奇怪)
.factory('configService', function($http){
...
return {
getConfig: function(){
return getConfig();
},
setConfig: function(config){
return setConfig(config);
}
};
})
这应该返回一个您可以使用的承诺。
但也许我错了,看看你的代码,它应该按照你的要求做。