它没有列出ng-repeat
。这段代码片有什么问题?
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="MyApp">
<div ng-init="courses = [{"Number":"CREOO11","Name":"Design Pattern 101","Instructor":"Yunus Emre KESKIN"},
{"Number":"CREOO12","Name":"Design Pattern 102","Instructor":"Yunus Emre KESKIN"},
{"Number":"CREOO13","Name":"Design Pattern 103","Instructor":"Yunus Emre KESKIN"}]">
<div class="row">
<table>
<tr>
<th> Course Number </th>
<th> Course Name </th>
<th> Instructor </th>
</tr>
<tr ng-repeat="c in courses">
<td> {{c.Number}} </td>
<td> {{c.Name}} </td>
<td> {{c.Instructor}} </td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
答案 0 :(得分:1)
上述代码中有两个问题: 1.在html文件中使用MyApp角度模块时,它不可用 2.初始化课程的方法不正确
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script>
angular.module('MyApp', [])
.controller('MyCntrl', function($scope) {
$scope.courses = [{"Number":"CREOO11","Name":"Design Pattern 101","Instructor":"Yunus Emre KESKIN"},
{"Number":"CREOO12","Name":"Design Pattern 102","Instructor":"Yunus Emre KESKIN"},
{"Number":"CREOO13","Name":"Design Pattern 103","Instructor":"Yunus Emre KESKIN"}];
});
</script>
<body>
<div ng-app="MyApp">
<div ng-controller="MyCntrl">
<div class="row">
<table>
<tr>
<th> Course Number </th>
<th> Course Name </th>
<th> Instructor </th>
</tr>
<tr ng-repeat="c in courses">
<td> {{c.Number}} </td>
<td> {{c.Name}} </td>
<td> {{c.Instructor}} </td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>