2017-02-08 3 views
0

У меня возникла проблема с файлом js. Мой js-файл не связан с файлом HTML. Пожалуйста, помогите мне.js file не ссылается на 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> " 

Ниже мой Угловая 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"}]; 

    }]); 

ответ

2

Ваш синтаксис массива неверен, вам нужны запятые, чтобы разделить ваши элементы массива:

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

Как только вы исправите это, он должен работать, см. Этот codepen.

+0

спасибо @ Dario. когда-нибудь я делаю такие глупые ошибки –

Смежные вопросы