简体   繁体   中英

Angular can get data from Web Api

Hi i try to get data from my web API with Angular but i get 404 not found the code is

Html code

<!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>

Angular code:

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);

thanks for the help

It seems to be a problem with that endpoint in your API side. Re-test you API endpoint if it's working correctly. You can check response using POSTMAN before integrate with your angular solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM