为什么数据没有显示在Angular JS的页面上

时间:2016-06-17 10:23:08

标签: angularjs

最近我的页面显示数据,但从昨天突然显示它。我很困惑我做错了什么。我检查得当,一切正常。 这是UI上的代码 -

<html xmlns="http://www.w3.org/1999/xhtml" ng-app="myApp">
<head runat="server">
    <title></title>
    <script src="Scripts/angular.js"></script>
    <script src="Scripts/jquery-1.8.3.min.js"></script>
    <script src="Scripts/angular-route.min.js"></script>
    <script src="script.js"></script>
    <script src="EmployeeServices.js"></script>
</head>

<body>
  <form id="form1" ng-controller="EmpCtrl" ng-submit="save()">
   <table border="1" style="text-align: center; margin-left: 410px;">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Age</th>
                    <th>City</th>
                    <th>Gender</th>
                    <th>Edit</th>
                    <th>Delete</th>
                </tr>
            </thead>
            <tbody>
                <tr ng-repeat="employee in employees">
                    <td>{{employee.Name}}</td>
                    <td ng-bind="employee.Age"></td>
                    <td ng-bind="employee.City"></td>
                    <td>{{employee.Gender && "Male" || "Female"}}</td>
                    <td><a href="#" ng-click="EditEmployee(employee.EmpId)">Edit</a> </td>
                    <td><a href="#" ng-click="DeleteEmployee(employee.EmpId)">Delete</a> </td>
                </tr>
            </tbody>
        </table>
    </form>
</body>
</html>

控制器代码 -

var app = angular.module('myApp', ['ngRoute']);
app.controller('EmpCtrl', function ($scope, $http, fetchEmpService) {
    $http.get("EmpWebService.asmx/GetEmp")
            .then(function (response) {
                $scope.employees = response.data;
            });
}

我还检查并意识到控制器正在以对象形式接收数据,但它没有在UI上显示

1 个答案:

答案 0 :(得分:0)

我认为你错过了“获取”网址开头的“/”。

var app = angular.module('myApp', ['ngRoute']);
app.controller('EmpCtrl', function ($scope, $http, fetchEmpService) {
    $http.get("/EmpWebService.asmx/GetEmp")
            .then(function (response) {
                $scope.employees = response.data;
            });
}

请验证。