js文件未链接到HTML文件

时间:2017-02-08 14:40:56

标签: html angularjs

我遇到了js文件的问题。我的js文件没有链接到HTML文件。请帮帮我。

HTML代码: "      

  <html>
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>   
    <script src="repeaters.js"></script>
    <link href = "Repeaters.css" type="text/CSS" rel="stylesheet">
</head>


<body ng-app="repeatModule">   <!-- root module-->


<div ng-controller="controlRepeater">  <!-- controller name--> 

<div>

<table>
    <thead>
        <tr>ID </tr>
        <tr> NAME</tr>
    </thead>
<tbody >

    <tr ng-repeat="product in products"> <!-- Great. Now let's add the repeat directive. It is important to understand that ngRepeat will repeat itself and its contents for each element in the collection. We must therefore apply it to the <tr> and not the <tbody>. -->
        <td>{{product.id}} </td>
        <td>{{product.name}} </td>

    </tr>
</tbody>
</table>       
</div>
 </div>   

  <div class="oddrow">   
 </div>

</body>

</html> "

以下是我的Angular js代码:

此js文件未链接到HTML代码。我该如何调试这类问题?

>   var myApp = angular.module('repeatModule', []) 
   .controller("controlRepeater", ["$scope", function ($scope) { 
   $scope.products = [      
   {id:1, name: "Hockey" }
   {id:2, name: "cricket" }
   {id:3, name: "pool" }
   {id:4, name: "badminton"}];

    }]);

1 个答案:

答案 0 :(得分:2)

您的数组语法错误,您需要用逗号分隔数组项:

$scope.products = [      
   {id:1, name: "Hockey" },
   {id:2, name: "cricket" },
   {id:3, name: "pool" },
   {id:4, name: "badminton"}
];

解决此问题后,它应该有效,请参阅此codepen