简体   繁体   中英

Angular.js $scope not binding after $http

The UI binds but with {{total}} showing as -1 I do see the console log 'data came back'. Why dont I see 99 ?

myModule.controller('dashboardCtrl', ['$scope', '$http'
    , function ($scope, $http) {
        $scope.total=-1;
        $http.get('api/controlPanel/dashboard').success(function (data) {
            $scope = data.stats;
            $scope.total=99; // just to make sure the value changes
            console.log('data came back');
        });
    }
]);

I read a lot of blogs talking about $scope.$apply yet it is undefined. Any help would be appreciated

My first inclination is that you are redefining the $scope object and so the bindings are not taking effect. I would try $scope.stats = data.stats instead to avoid this problem.

This might be good to read: https://docs.angularjs.org/guide/scope

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM