I know that something like that, will work:
<span ng-repeat="item in items">{{item.name}}</span>
How can I do the same with plain text?
I would like to append {{items[0].name}}, {{items[1].name}}, {{items[2].name}}
to my html in plain text :)
In my case, inside an input: <input type="hidden" name="items" value="{{items[0].name}},{{items[1].name}},{{items[2].name}}"/>
Thanks guys!
I know that something like that, will work:
<span ng-repeat="item in items">{{item.name}}</span>
How can I do the same with plain text?
I would like to append {{items[0].name}}, {{items[1].name}}, {{items[2].name}}
to my html in plain text :)
In my case, inside an input: <input type="hidden" name="items" value="{{items[0].name}},{{items[1].name}},{{items[2].name}}"/>
Thanks guys!
Share Improve this question asked Jul 12, 2014 at 22:55 DeptrocoDeptroco 1291 gold badge3 silver badges11 bronze badges 5- I don't think you can pass multiple values at once in a hidden field : stackoverflow./questions/3073001/… – Christian Bonato Commented Jul 12, 2014 at 22:57
- It's an unique value, spilted by as :) – Deptroco Commented Jul 12, 2014 at 22:58
- If you need to know the "key" passed when you are fetching values through ng-repeat, keep the original statement, and try {{$index}}. – Christian Bonato Commented Jul 12, 2014 at 22:59
- "unique value, spilted by as" -> Not very elegant... What are you trying to achieve? Pass x values according to user's selection? – Christian Bonato Commented Jul 12, 2014 at 23:01
-
for
input
just useng-model
, to append can usesplit()
to create array which can run throughng-repeat
– charlietfl Commented Jul 12, 2014 at 23:12
1 Answer
Reset to default 6I would either use a simple controller function:
<input name="items" value="{{mas(items)}}">
//in your controller.js
$scope.mas = function mas(items) {
return items.join(",");
}
Another option might be a filter:
<input name="items" value="{{ items | mas }}">
//in your javascript
myApp.filter("mas", function () {
return function masFilter(list) {
return list.join(",");
}
});
But in general keep the logic in your templates straightforward and move to controllers, filters, or directives when the built-in ones are not sufficient.