我从角度服务调用Web-Api并将数据返回到我的角度控制器。 $ scope。$ watch显示正确的数据,但视图不会更改相关数据。
我的Angularjs-Service是,
BDayModule.service(“serviceUser”,function($ http){
this.getData = function () {
return $http.get('/Users/listAll').then(function (success) {
console.log("success.data 1 = " + success.data);
return success.data;
},
function (error) {
alert("Insertion fail");
},
function (process) {
});
};
});
我的angularjs-controller是,
BDayModule.controller(“ControllerUsers”,函数($ scope,$ interval,serviceUser,commonFunction){
$scope.allBDayData = [];
$scope.getAllUsers = function () {
var myDataPromise = serviceUser.getData();
myDataPromise.then(function (result) {
console.log("success.data 2 = " + result);
$scope.allBDayData = result;
$scope.$watch('allBDayData',
function (newValue, oldValue) {
console.log('allBDayData Changed');
console.log(newValue);
console.log(oldValue);
});
});
}
});
<div ng-controller="ControllerUsers">
<input type="button" value="Show all" ng-click="getAllUsers()" />
<table class="table table-bordered table-responsive table-hover">
<caption>
<span class="col-lg-2 col-sm-3"><input type="text" class="form-control" ng-model="Search.$" placeholder="Full filter" /></span>
</caption>
<thead>
<tr>
<th>User Name : <input type="text" ng-model="Search.UserName" placeholder="Filter" /></th>
<th>Email Address</th>
<th>First Name</th>
<th>Birth Date</th>
<th>Age</th>
<th><span aria-hidden="true" class="glyphicon glyphicon-edit"></span></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="data in allBDayData | filter: Search">
<td>{{data.UserName}}</td>
<td>{{data.EmailId}}</td>
<td>{{data.Name}}</td>
<td>{{data.BirthDate}}</td>
<td>{{data.Age}}</td>
<td><input type="button" value="edit" class="btn btn-sm btn-success" style="width: 90px;" /></td>
</tr>
</tbody>
</table>
</div>
我点击的按钮位于母版页中,
<li><a ng-controller="ControllerUsers" href="#list" ng-click="getAllUsers()"> Show All </a>
这个按钮正确地基于路由呈现页面,并且也触发了getAllUsers()。但没有改变我的观察结果......