Create Button from data in scope

Description

The following code shows how to Create Button from data in scope.

Example


<!DOCTYPE html>
<html  ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
<script type='text/javascript'>
function ctrl($scope) {<!--from   w ww  .  j a  v a  2 s .c  o  m-->
    $scope.btns = [{
        label: "One",
        state: false
    }, {
        label: "Two",
        state: true
    }, {
        label: "Three",
        state: false
    }];

    $scope.toggle = function () {
        this.b.state = !this.b.state;
    };
}
</script>
</head>
<body ng-app ng-controller="ctrl">
  <button ng-click="toggle()" ng-class="{on:b.state}" ng-repeat="b in btns">{{b.label}}</button>
</body>
</html>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Example »




Controller
Directives
Expression
Filter
Form
Inject
Scope
Server
Style
Template
Utilities