//anular model
var app = angular.module('myapp', []);
这是获取数据的服务
app.service('EmployeeService', function ($http) {
this.getEmployees = function () {
return this.$http.get('Employee/getall');
}
});
角度控制器
app.controller('EmployeeController', function ($scope, EmployeeService) {
function getEmployeeList() {
EmployeeService.getEmployeeList.then(function (emp) {
$scope.EmployeeList = emp.data;
}, function (error) {
});
}
});
控制器返回 JSON 结果
public JsonResult getall()
{
List<Countries> contry = new List<Countries>() {
new Countries({id=1,Name="ahmad" ,LastName="ali" },
new Countries() {id=1,Name="kami" ,LastName="ali" },
new Countries() {id=1,Name="billo" ,LastName="ali" },
new Countries() {id=1,Name="juni" ,LastName="ali" },
new Countries() {id=1,Name="podeena" ,LastName="ali" } };
return Json(contry, JsonRequestBehavior.AllowGet);
}
这是视图
编号 名字 姓 {{e.id}} {{e.Name}} {{e.LastName}}这些是链接
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/angular.min.js"></script>
<script src="~/Scripts/angular-route.min.js"></script>
<script src="~/Angular/Module.js"></script>
<script src="~/Angular/Service.js"></script>
<script src="~/Angular/empController.js"></script>
小问题。您需要一个员工列表,但返回一个国家/地区列表对象。在线$scope.EmployeeList = emp.data
$scope.EmployeeList = emp.country
.在哪里显示员工列表的代码?是否在$scope点放置了断点。EmployeeList get设置以确保数据得到恢复。