8 Example(s) of Ng-List


Description :

Ng-list directive display the textbox text in array form seprated by comma.Textbox value bind to list variable which will display the text.


Ng-List Example - 1
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script>
</head>
<body ng-app>
    <div>
        Name With (,) separate: <input type="text" ng-model="list" ng-list /><br />
        <pre>Names:{{list}}</pre>
    </div>
</body>
</html>

Output

Description :

Ng-list directive display the textbox text in json format seprated by comma.Textbox value bind to name variable which will display the text.


Ng-List Example - 2
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script>
</head>
<body ng-app>
    <div>
        <p>Type comma ( , ) separated names.</p>
        <textarea ng-model="name" ng-list=","></textarea>
        <pre>{{name|json}}</pre>
    </div>
</body>
</html>

Output

Description :

In this example the textbox is bind with the listNum array, when you type comma separated numbers in the textbox the ng-list directive make list of the binded numbers and show in the json format.


Ng-List Example - 3
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script>
</head>
<body ng-app="app">
    <div ng-controller="controllerName">
        <p>Type comma ( , ) separated number.</p>
        <input type="text" ng-model="listNum" placeholder="Enter numbers" ng-list size=60>
        <pre>{{listNum|json}}</pre>
    </div>
    <script>
    var app = angular.module("app", []);
    app.controller('controllerName', ['$scope', function ($scope) {
      $scope.listNum=[2,3,4]
    }]);
</script>
</body>
</html>

Output

Description :

Ng-list directive display the textbox text in array form seprated by "-".Textbox value bind to list variable which will display the text.


Ng-List Example - 4
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script>
</head>
<body ng-app="app">
    <div ng-controller="controllerName">
        <p>Type dash ( - ) separated names.</p><input type="text" ng-model="list" ng-list="-"><br />
        {{list}}
    </div>
    <script>
    var app = angular.module("app", []);
    app.controller('controllerName', ['$scope', function ($scope) {
        $scope.list = ["Learn", "It"];
    }]);
</script>
</body>
</html>

Output

Description :

Ng-list directive display the textbox text in json format seprated by "-".Textbox value bind to list variable which will display the text.Ng-trim=false means it will not trim the value of textbox.


Ng-List Example - 5
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script>
</head>
<body ng-app="app">
    <div ng-controller="controllerName">
        <p>Type dash( - ) separated names.(ng-trim='false')</p><input type="text" ng-model="list" ng-list="-" ng-trim="false"><br />
        <pre>{{list|json}}</pre> 
    </div>
    <script>
    var app = angular.module("app", []);
    app.controller('controllerName', ['$scope', function ($scope) {
        $scope.list = ["Learn", "It"];
    }]);
</script>
</body>
</html>

Output

Description :

Ng-list directive display the textbox text in json format.Textbox value bind to list variable which will display the text. It will not trim the input.


Ng-List Example - 6
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script>
</head>
<body ng-app="app">
    <div ng-controller="controllerName">
        <p>Type space (' ') separated names.</p><input type="text" ng-model="list" ng-list=" " ng-trim="false"><br />
        <pre>{{list|json}}</pre> 
    </div>
    <script>
    var app = angular.module("app", []);
    app.controller('controllerName', ['$scope', function ($scope) {
        $scope.list = ["Learn", "It"];
    }]);
</script>
</body>
</html>

Output

Description :

Ng-list directive display the textbox text in json format.Textbox value bind to listvariable which will display the text. It will trim the value of input.


Ng-List Example - 7
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script>
</head>
<body ng-app>
    <div>
        <p>Type names.</p><input type="text" ng-model="list" ng-list=" " ng-trim="true"><br />
        <pre>{{list|json}}</pre>
    </div>
</body>
</html>

Output

Description :

Ng-List-8


Ng-List Example - 8
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script>
</head>
<body ng-app>
    <div>
        <p>Enter Your Favourite colours name with comma seprated.</p><textarea ng-model="colours" ng-list ng-trim="true"></textarea><br />
    </div>
    <h4>This is the list of your favourite colours.</h4>
    <ol>
        <li ng-repeat="colour in colours">{{colour}}</li>
    </ol>
</body>
</html>

Output