ng-repeat不绑定数据

时间:2016-07-09 19:22:16

标签: angularjs

我是angularjs的新手,并尝试使用ng-repeat指令示例将数据绑定到HTML表元素。 我的js文件位于脚本位置,它有一个模块和控制器,其中一些数据附加到该控制器中的作用域对象。

现在我想要的只是将数据绑定到我的HTML表元素并使用ng-repeat显示数据。我正在使用ng-repeat,因为我要在表格中显示多行。

这是我的角度代码:

  

`

/// <reference path="angular.min.js" />
/// <reference path="angular.js" />



var angularModule = angular.module("TestMyModule", []);
    angularModule.controller("MyController", function ($scope) {
    var employee  = [
                    {FirstName: "GGG",LastName: "SSS",MiddleName:"G"},
                    {FirstName: "G",LastName: "S",MiddleName: "GG"},
                    {FirstName: "GGS",LastName: "GSS",MiddleName: "GS"},
                    {FirstName: "Go",LastName: "Sa",MiddleName: "Gu"},
                    {FirstName: "Goo",LastName: "SAA",MiddleName: "Gu"}
    ];
    debugger;
    $scope.employee = employee;

});

`

以下是我的HTML代码

<!DOCTYPE html>
<html ng-app="angularModule">
<head>
    <title>AngularJS Example</title>
    <script src="Scripts/AngularExample.js"></script>
    <script src="Scripts/angular.min.js"></script>

</head>
<body >
        <table ng-controller="MyController">
            <thead>
                <tr>
                    <th>First Name</th>
                    <th>Last Name</th>
                    <th>Middle Name</th>
                </tr>
            </thead>
            <tbody>
                <tr ng-repeat="employees in employee">
                    <td>{{employees.FirstName}}</td>
                    <td>{{employees.LastName}}</td>
                    <td>{{employees.MiddleName}}</td>
                </tr>
            </tbody>
        </table>
</body>
</html>

以下是我得到的输出:

 First Name                 Last Name            Middle Name

{{employees.FirstName}} {{employees.LastName}} {{employees.MiddleName}}

使用浏览器调试工具,我发现了以下错误,但不确定如何解决:

AngularExample.js:6 Uncaught ReferenceError: angular is not defined
angular.js:4631 Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.5.7/$injector/modulerr?p0=angularModule&p1=Er…20c%20(http%3A%2F%2Flocalhost%3A2785%2FScripts%2Fangular.min.js%3A20%3A359)
firebug-lite.js:11883 Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
firebug-lite.js:30905 Uncaught TypeError: Cannot read property 'push' of undefined

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

更改文件序列的加载方式,角度应该在AngularExample.js之前加载,以便首先加载库API。

<script src="Scripts/angular.min.js"></script>
<script src="Scripts/AngularExample.js"></script>

ng-app应该是ng-app="TestMyModule",它是角度模块名称。