ng-show="my.message“在http成功时设置为true,但它不更新视图。
下面是我的代码:
控制器Js:
lgControllers.controller('FormCtrl', function($scope, $http) {
$scope.my = {
message: false
};
$scope.submitForm = function() {
$http({
url: "../saket/ajax.php",
data: "email_id=" + $scope.form.emailaddress + "&category_id=" + cat_num + "&action=subscribe",
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
}).success(function(data) {
$scope.my = {
message: true
};
console.log(data); // http is success
console.log($scope.my.message); // gives true
}).error(function(err) {
"ERR", console.log(err)
})
};
});Index.html:
<div ng-controller="FormCtrl">
<div ng-show="my.message">It worked!</div>
</div>my.message在console中为true,但div在视图中保持隐藏状态。
我不知道问题出在哪里。
发布于 2015-06-24 19:22:07
会不会是您覆盖了message属性,而angularjs正在丢失引用?
$scope.my = {
message: true
;试试看:
$scope.my.message = true;https://stackoverflow.com/questions/31024934
复制相似问题