Angular.js $scope 在 $http 之后没有绑定

Angular.js $scope not binding after $http

UI 绑定但 {{total}} 显示为 -1 我确实看到了控制台日志 'data came back'。为什么我看不到 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');
        });
    }
]);

我读了很多关于 $scope.$apply 的博客,但它是未定义的。任何帮助将不胜感激

我的第一个想法是您正在重新定义 $scope 对象,因此绑定没有生效。我会尝试 $scope.stats = data.stats 来避免这个问题。

这可能适合阅读:https://docs.angularjs.org/guide/scope

希望对您有所帮助!