我有:
app.controller('items', function($scope){
$scope.items = [
{'id':1, 'name':'randomOne'},
{'id':2, 'name':'whatEverName'}
];
});
我想要什么:
<input value="1,2"/>
我了解了ng-repeat
,但它只能用在html标签上。有没有办法用 AngularJS 来实现这一点?
谢谢!
最佳答案
使用过滤器:
.filter('getIds', function () {
return function (items) {
return items && items.map(function (item) {
return item.id;
}).join(',');
}
})
在你的html中:
<input value="{{ items | getIds }}" />
示例 Plunker: http://plnkr.co/edit/ifHKzWqxtErQQVToMNsH?p=preview
关于javascript - AngularJS : ng-repeat for plain text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24718592/