Add new item to UL list

Description

The following code shows how to add new item to UL list.

Example


<!DOCTYPE html>
<html  ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
<!--from  w  w w  .j a v  a2 s.  c  om-->
<style type='text/css'>
ul {
    height: 150px;
    overflow: scroll;
}
</style>
</head>
<body ng-app="myApp">
  <div ng-controller="MyCtrl">
    <button ng-click="add()">Add</button>
    <ul>
        <li ng-repeat="item in list">{{item}}</li>
    </ul>
</div>

<script type='text/javascript'>

var myApp = angular.module('myApp',[]);

function MyCtrl($scope) {
    $scope.list = ["item 1", "item 2","item 3","item 4","item 5"];
    $scope.add = function() {
        $scope.list.push("new item");
    }
}
</script>
</body>
</html>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Example »




Controller
Directives
Expression
Filter
Form
Inject
Scope
Server
Style
Template
Utilities