javascript - Angular ngOptions Slice or ellipse -
i've got long sentences showing in ngoptions populating api.. how can slice em end ( red... or blue...) dots @ end of word..., ummm may should try creating filter should length of str , slice depending how many characters want..any appreciated.
$scope.colors = [ {name:'blacksomerandomwords', shade:'dark'}, {name:'whitesomerandomwords', shade:'light', notanoption: true}, {name:'redsomerandomwords', shade:'dark'}, {name:'bluesomerandomwords', shade:'dark', notanoption: true}, {name:'yellowsomerandomwords', shade:'light', notanoption: false} ]; <select ng-model="mycolor" ng-options="color.name color in colors"></select>
yourapp.filter('short', function() { // pass in collection, property shorten , max length return function(values, property, length) { angular.foreach(values, function(value) { value[property] = value[property].length <= length ? value[property] : value[property].substr(0, length) + '...'; }); return values; }; }); <select ng-model="mycolor" ng-options="color.name color in colors | short:'name':6"> </select>
related plunker here http://plnkr.co/edit/mvky0h
Comments
Post a Comment