您好我尝试使用Angular从我的Web API获取数据,但是我发现404没有找到代码
Html代码
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="utf-8" />
<title>Simple Web Application</title>
<script src="Scripts/angular.js"></script>
<script src="Scripts/script.js"></script>
</head>
<body >
<div ng-controller="MainController">
<table>
<tr>
<td>ID</td>
<td>Name</td>
</tr>
<tr ng-repeat="emp in employees">
<td>{{emp.id}}</td>
<td>{{emp.Ename}}</td>
</tr>
</table>
</div>
</body>
</html>
角色代码:
var url = "http://localhost:65125/api/Empyloee";
var myApp = angular.module("myApp", []);
var MainController = function ($scope, $http) {
var onSucess = function (response) { $scope.employees = response.data};
var onFailure = function (reason) { $scope.error = reason };
var getAllEmployees = function () {
$http.get(url)
.then(onSucess ,onFailure)
};
getAllEmployees();
};
myApp.controller("MainController", MainController);
感谢您的帮助
答案 0 :(得分:2)
API端的端点似乎存在问题。如果API端点正常工作,请重新测试它。在与角度解决方案集成之前,您可以使用POSTMAN检查响应。