我的数据对象没有在 html 中显示!
我正在使用 parse.com,当我使用 console.log(results) 时,我可以向下钻取并在检查窗口中查看我的对象属性。
app.controller('membershipCtrl', ['$scope', function($scope) {
var membership = Parse.Object.extend("Membership");
var query = new Parse.Query(membership);
query.ascending("priceDate").greaterThan('priceDate', currentTime).limit(1);
query.first({
success: function(results) {
$scope = results;
console.log($scope);
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
});
}]);
从检查窗口:
attributes: Object
price: 90
priceDate: Mon Feb 01 2016 11:17:00 GMT-0700 (MST)
priceDescription: "Thru Sept 2016"
我的 html 是:
<div ng-app="myApp" ng-controller="membershipCtrl">
{{price}}{{priceDescription}}
</div>
最佳答案
您的成功函数正在覆盖整个 $scope
变量,而不是在其中放置值。您需要执行后者,以便您的 View 实际上可以访问任何内容:
success: function(results) {
$scope.price = results.price;
$scope.priceDescription = results.priceDescription;
console.log($scope.price);
console.log($scope.priceDescription);
},
关于javascript - 来自 Controller 的 Angular 对象未在 html 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34847379/