2016-02-14 78 views
0

我試圖讓一個例子類似的例子在https://angularjs.org/角JS - NG-重複工作不正常

這裏是JS撥弄我創建。

有人可以幫忙。這有什麼問題?

HTML是..

<h2> 
To Do 
</h2> 
<div ng-controller="ToDoListController as todoList"> 
    <ul> 
    <li ng-repeat="todo in todoList.todos"> 
     {{todo.text}} 
    </li> 
    </ul> 
</div> 

和JS部分是

angular.module('todoApp',[]).controller('ToDoListController', 
function(){ 
var todoList = this; 
    todoList.todos = [ 
     {text:'learn angular', done:true}, 
     {text:'build an angular app', done:false}]; 
}); 

Link了JS提琴。

回答

1

我編輯你的小提琴。有兩個問題

  1. 體標籤應包含在<>
  2. 角JS沒有被使用
+0

所以你的意思是我需要添加作爲body標籤? – Ketan

+0

@ketan是的,否則它會顯示'body ng-app =「todoApp」'作爲文本 – Amit

+0

謝謝你。但是我將Angular JS作爲外部js加入了小提琴。有沒有其他的方式來添加這個? – Ketan

0

控制器

angular.module('todoApp',[]).controller('ToDoListController',function(){ 
$scope.todoList = []; 
$scope.todoList = [ 
    {text:'learn angular', done:true}, 
    {text:'build an angular app', done:false}]; 
}); 

HTML

<html> 
<body ng-app="myApp" > 
<h2> 
To Do 
</h2> 
<div ng-controller="ToDoListController"> 
    <ul> 
    <li ng-repeat="todo in todoList"> 
     {{todo.text}} 
    </li> 
    </ul> 
</div> 
</body> 
</html> 
+0

難道我們不需要文字嗎?爲什麼? – Ketan

+0

你可以使用todo.text,所以你只會得到文本值而不是整個對象 –

0

您需要訪問屬性以這種方式:

{{todo["text"]}} 

我更新了你的小提琴。