【发布时间】:2019-12-06 18:05:37
【问题描述】:
我正在尝试使用 Angular ng-repeat 将 JSON 请求的结果放入表中,但没有任何反应。控制台未显示错误,.NET 控制器中的断点未命中。
应用控制器代码:
var app = angular.module('angularTable', []);
app.controller('listdata', function ($scope, $http) {
$scope.contacts = [];
$http({ method: 'GET', url: '/Contacts/GetContacts/' }).success(function (response) {
$scope.contacts = response;
});
});
.NET 控制器
[HttpGet]
public JsonResult GetContacts()
{
var data = db.Contacts.Include(x => x.Cities).Include(a => a.Groups);
return Json(data);
}
HTML:
<div ng-app ="angularTable">
<table class="table table-hover" ng-controller="listdata">
<thead>
<tr>
<th>Name</th>
<th>Phone</a></th>
<th>Group</th>
<th>City</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in contacts">
<td>{{item.name}}</td>
<td>{{item.area}} {{item.phone}}</td>
<td>{{item.group.description}}</td>
<td>{{item.city.name}}</td>
<td>
<a asp-route-id="{{item.id_Contact}}">Send Message | </a>
<a asp-route-id="{{item.id_Contact}}">Edit | </a>
<a asp-route-id="{{item.id_Contact}}" asp-action="Delete">Delete</a>
</td>
</tr>
</tbody>
</table>
</div>
将此 CDN 用于 AngularJS:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
【问题讨论】:
-
.success方法一直是removed from the AngularJS framework。 -
浏览器开发者控制台的网络标签是否显示请求?
-
先尝试使用浏览器点击网址,例如 localhost/Contacts/GetContacts 。看看它是否返回 JSON ,然后修复你的角度代码
标签: javascript c# angularjs asp.net-core