Angular JS-ng-repeat工作不正常

时间:2016-02-14 03:34:57

标签: javascript html angularjs

我尝试举例说明https://angularjs.org/

中的示例

这是我创建的JS小提琴。

有人可以提供帮助。这有什么问题?

HTML is ..

<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}];
});
JS小提琴

Link

3 个答案:

答案 0 :(得分:1)

我编辑了你的小提琴。有两个问题

  1. 正文标记应包含在&lt;&gt;
  2. 没有使用Angular js

答案 1 :(得分:0)

<强> CONTROLLER

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>

答案 2 :(得分:0)

您需要以这种方式访问​​该属性:

{{todo["text"]}} 

我对你的小提琴做了更新。

相关问题