- AngularJS provides ngList built-in directive for separating input string.
- It can be used with ngTrim for handling white space in trailing.
- In this demo "We will see how to use ngList directive in input type text".
- Below code has the fruit array which is separated using default separator and with new separator hyphen -.
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
<meta charset="utf-8">
<title>AngularJS ngList Example</title>
</head>
<body ng-controller="MyController">
<h3>ngList directive separator (,) example</h3>
<input ng-model="fruits" ng-list required><br/>
<pre> {{fruits}}</pre>
<h3>ngList directive separator (-) example</h3>
<input ng-model="fruits" ng-list="-" required><br/>
<pre> {{fruits}}</pre>
<h3>ngList directive separator (-) example</h3>
<input ng-model="fruits1" ng-list="-" ng-trim='false' required><br/>
<pre> {{fruits1|json}}</pre>
</body>
</html>
- The javascript code for this demo is as follows:-
var myApp= angular.module("myApp",[]);
myApp.controller("MyController",
["$scope", function($scope){
$scope.fruits=["Apple","Mango","Grapes","Orange","Banana"];
$scope.fruits1=["Apple ","Mango","Grapes","Orange","Banana"];
}]);