Asp.net mvc Web api结果更新模型,但不在angularjs中更新视图
我从angular服务调用Web Api,并将数据返回到angular控制器。 $scope.$watch显示正确的数据,但视图未更改相关数据 我的Angularjs服务是 服务(“serviceUser”,函数($http){ })) 我的angularjs控制器是 控制器(“ControllerUsers”,函数($scope、$interval、serviceUser、commonFunction){ })) 在我看来,,Asp.net mvc Web api结果更新模型,但不在angularjs中更新视图,asp.net-mvc,angularjs,angularjs-scope,angularjs-service,Asp.net Mvc,Angularjs,Angularjs Scope,Angularjs Service,我从angular服务调用Web Api,并将数据返回到angular控制器。 $scope.$watch显示正确的数据,但视图未更改相关数据 我的Angularjs服务是 服务(“serviceUser”,函数($http){ })) 我的angularjs控制器是 控制器(“ControllerUsers”,函数($scope、$interval、serviceUser、commonFunction){ })) 在我看来,, 用户名: 电子邮件地址 名字 出生日期 年龄 {{data.Us
用户名:
电子邮件地址
名字
出生日期
年龄
{{data.UserName}
{{data.EmailId}
{{data.Name}
{{data.BirthDate}
{{data.Age}
我单击的按钮位于母版页中
<li><a ng-controller="ControllerUsers" href="#list" ng-click="getAllUsers()"> Show All </a>
此按钮根据路由正确呈现页面,并触发getAllUsers()。但不会更改我的视图结果…当我单击同一视图上的按钮时,数据呈现良好,所以服务返回正确的数据格式,但我想在单击母版页按钮时使工作方式相同。两者都在控制台上返回相同的数据。我尝试使用$scope.$apply,但它给我的错误是:$digest已经在工作中。不需要该摘要,只需在plnkr网站上为代码创建一个plnkr。我正在使用SQL SERVER和ASP.NET MVC。。。所以为了便于代码检查,我在plnkr上添加了它。。。请参考。。。我的API调用在页面呈现之前返回结果。。。但这不应该是不在视图上呈现数据的原因。。。r8?您的代码存在的一个问题是,您的脚本都在head部分,这会降低页面呈现/加载的速度,而且我不知道如何注入listAll.cshtml模板?
$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>