这是配置文件config.js
:AngularJS视图不能更新
.state ('home', {
url: '/home',
templateUrl: 'views/common.html'
})
.state ('home.mypage', {
url: '/mypage',
templateUrl: 'views/mypage.html'
})
这里是common.html
:
<header id="header" data-ng-include src="'views/template/header.html'"></header>
<section id="main">
<aside id="leftside" data-ng-include src="'views/template/leftside.html'"></aside>
<aside id="rightside" data-ng-include src="'views/template/rightside.html'" data-ng-controller="mypageCtrl"></aside>
<section id="content" class="page-view" data-ui-view></section>
</section>
<footer id="footer" data-ng-include src="'views/template/footer.html'"></footer>
rightside.html包含输入和API调用搜索按钮, mypage.html包含那样的东西<div class="container ng-scope" data-ng-controller="mypageCtrl">
。
当阿贾克斯成功:
function (data) {
$scope.results = data.results;
$scope.pagination = data._meta.pagination;
}
当我要求我的空间和第一次出现的结果是寻呼机点击即使确定。但是当我单击rightside.html中的搜索按钮时,即使ajax响应也会导致view(mypage.html)不会更新。
我错了什么?如何在模型发生变化时更新视图?
编辑: 这是mypageController.js
materialAdmin
.controller('mypageCtrl', function($location, $scope, mypageService) {
$scope.search = function(conditions) {
return (mypageService.search(conditions).then(
function (data) {
$scope.results = data.results;
$scope.pagination = data._meta.pagination;
},
function (error) {
console.log(error);
}
));
};
$scope.search($scope.conditions); // Initial search when request page
})
和mypageService.js
materialAdmin.service("mypageService", ['$http', '$q', function($http, $q) {
return {
search: search
// and more functions
};
function search(conditions) {
return ($http.post(
BASE_URL + "/search", conditions).then(
handleSuccess,
function (response) {
handleError(response, $q)
}
));
}
}]);
你在用什么'$ http'或'$ .ajax'? – Satpal
我使用'$ http'。 –