2017-07-07 120 views
-3

獲得在角內陣列JSON對象值我有JSON的對象數組象下面這樣:如何使用NG-重複

todoList: 
     [ { todo: 'dummy1', id: 595b9c2bb4b9992a4041d6e3 }, 
     { todo: 'dummy2', id: 595e4ffc62e38e3844f8d43a }, 
     { todo: 'dummy3', id: 595e4fff62e38e3844f8d43b }, 
     { todo: 'dummy4', id: 595f00c1d18df61840ad1ba3 } ] 

我想用用在我看來,待辦事項場NG-重複像下面

​​

請問我可以從待辦事項列表中只訪問待辦事項的方式嗎?

回答

1

使用{{todo.todo}}

<div ng-repeat ="todo in todoList"> 
    <label> 
    {{ todo.todo}} 
    </label> 
</div> 

DEMO

var app = angular.module('myApp', []); 
 
app.controller('AppCtrl', function($scope, $http) { 
 
$scope.todoList= 
 
     [ { todo: 'dummy1', id: "595b9c2bb4b9992a4041d6e3" }, 
 
     { todo: 'dummy2', id: "595e4ffc62e38e3844f8d43a" }, 
 
     { todo: 'dummy3', id: "595e4fff62e38e3844f8d43b" }, 
 
     { todo: 'dummy4', id: "595f00c1d18df61840ad1ba3" } ]; 
 
});
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
</head> 
 

 
<body> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> 
 
    <div ng-app="myApp" ng-controller="AppCtrl"> 
 
<div ng-repeat ="todo in todoList"> 
 
    <label> 
 
    {{ todo.todo }} 
 
    </label> 
 
</div> 
 
    </div> 
 
</body> 
 

 
</html>

+0

由於它的工作 –

1

您可以使用

<div ng-repeat ="todo in todoList"> 
    <label> 
    {{ todo.todo }} 
    </label> 
    <label> 
    {{ todo.id}} 
    </label> 
</div> 

如果你想調試,你可以使用json filter來打印json對象。

<div ng-repeat ="todo in todoList"> 
    <label> 
    {{ todo|json}} 
    </label> 
</div> 
1

這裏待辦事項變得todolist的對象一個對象,那麼你可以從訪問屬性,像todo.todo和todo.id

<div ng-repeat ="todo in todoList"> 
<label> 
    {{ todo.todo }} 
</label> 
</div>