AngularJS ng-list example

AngularJS ng-list directive can be used in text input and it converts between a delimited string and an array of strings. The default delimiter is a comma followed by a space and it can be changed by specifying a delimiter as ng-list value.

Example1

<div ng-app="myApp" ng-controller='MyCtrl'>
  <input type="text" ng-model="list1" ng-list><br>
  {{list1}}
</div>

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js"></script>
<script>
  var module = angular.module('myApp', []);
  module.controller('MyCtrl', function($scope) {
    $scope.list1 = ["v1", "v2", "v3", "v4"];
  });
</script>
refresh

Example2

<div ng-app="myApp" ng-controller='MyCtrl'>
  <textarea ng-model="list1" ng-list="&#10;" ng-trim="false"></textarea><br>
  {{list1}}
</div>

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js"></script>
<script>
  var module = angular.module('myApp', []);
  module.controller('MyCtrl', function($scope) {
    $scope.list1 = ["v1", "v2", "v3", "v4"];
  });
</script>
refresh
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments