我能够点击控制器方法并能够返回数据
[HttpPost]
public JsonResult GetAppsList()
{
var Apps = DataModel.ApplicationMasters.ToList();
return Json(new { appslist = Apps });
// return AppsList;
}
但在角度js中无法获取数据
myApp.controller('SpicyController', ['$scope','$http', function ($scope,$http) {
$http({
method: 'POST',
url: 'Home/GetAppsList'
}).then(function (response) {
$scope.appslist = response.data.appslist; }, function (error) {console.log(error);});}]);
在视图中
<div class="main" ng-app="spiceApp">
<div ng-controller="SpicyController">
<table>
<tr ng-repeat="app in appslist">
<td>
{{app.Name}}
</td>
</tr>
</table>
</div>
</div>
你能帮我解释为什么我无法显示结果吗?
答案 0 :(得分:1)
<div class="main" ng-app="spiceApp">
<div ng-controller="SpicyController">
<table>
<tr ng-repeat="(index,data) in appslist">
<td>
{{data.Name}}
</td>
</tr>
</table>
</div>
</div>
applist是一个对象。要在对象上应用ng-repeat,请写下ng-repeat=(index,data) in applist
。
myApp.controller('SpicyController', ['$scope','$http', function ($scope,$http) {
$http({
method: 'POST',
type:'json',
url: 'Home/GetAppsList'
}).then(function (response) {
$scope.appslist = response.data.appslist; }, function (error) {console.log(error);});}]);