javascript - Use the pipe character in an Angular Filter expression -
i use '|' character in angular 1 filter expression lie
{{ ctrl.items | map: 'name|id' | join: ',' }}   is there kind of character escaping use? know | character used calling filter, use concat 2 properties 'name' , 'id'.
and yes, know write function in controller concatenate 2 properties i'm interested if there way in expression.
ps: filter map , join repo: https://github.com/a8m/angular-filter
update:
in controller:
ctrl.items = [{ name: 'ape', id:1 }, { name: 'john', id:2 }];   in template:
<input type='hidden' value="{{ ctrl.items | map: 'name|id' | join: ',' }}" >   expected output:
<input type='hidden' value="ape|1,john|2" >      
you have create custom filter form value mentioned you.
var app = angular.module('myapp', []); app.filter('map', function() {   return function(input, propname) {   var prop = propname.split("|");   return input.map(function(item) {   return item[prop[0]] +"|"+ item[prop[1]];    });   }; });   and input text
<input type="text" value="{{(ctrl.items | map:'name|id').join(',')}}"/>   please find working plnkr working plnkr
Comments
Post a Comment