ng-click to call a function in scope

Description

The following code shows how to use ng-click to call a function 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'>
<!-- w  w  w .j ava 2 s  .c  o m-->
function Ctrl1($scope) {
    $scope.test = function(callback){
        eval(callback);
    };
}
</script>
</head>
<body>
  <div ng-app="">
  <div ng-controller="Ctrl1">
      <button ng-click="test('console.log(\'pushed\');')">Push Me</button>
  </div>
</div>
</body>
</html>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Example »




Controller
Directives
Expression
Filter
Form
Inject
Scope
Server
Style
Template
Utilities