[英]Angular.js $scope not binding after $http
UI綁定了,但{{total}}顯示為-1,但我確實看到了控制台日志“數據返回”。 為什么我看不到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
希望這可以幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.