Angular JS - ng-repeat无法正常工作

Angular JS - ng-repeat is not working properly

本文关键字:常工作 工作 JS ng-repeat Angular      更新时间:2023-09-26

我试图做一个类似于 https://angularjs.org/中的例子

的例子

这是我创建的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}];
});

JS小提琴的链接。

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

  1. 正文标签应附在<>
  2. 未使用 Angular js

您需要通过以下方式访问该属性:

{{todo["text"]}} 

我对你的小提琴进行了更新。

控制器

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>