2016-02-14 79 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"]}} 

我更新了你的小提琴。