Weird angularjs behavior returning "TypeError: Unable to assign read-only property"

I have encountered strange behavior from 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();
            });
    };
});

      

When I do console.log (data), I get a URL instead of an object from my localhost that never got hit.

/Users/rodrigoqueirolo/Desktop/factory/public/index.html 

      

I think the problem is with credentials urls, but surprisingly I have other 6 routes doing the same (CRUD). Here is the complete error when I click on the input form.

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) 

      

thank

+3


source to share


1 answer


I'm not a javascript expert, but here's my take:

change your service return to return a function that runs the function (odd sounding)

.factory('configService', function($http){
    ...

    return {
        getConfig: function(){
            return getConfig();
        }, 
        setConfig: function(config){
            return setConfig(config);
        }
    };
})

      



This should return a promise that you can use.

But maybe I am wrong, looking at your code, it should do as you ask.

0


source







All Articles