javascript - Clickable cell in Angularjs -
i can create clickable cells in pure js, doesn't work when trying simple using angularjs: when clicking on cell, complained dum
function doesn't exit. idea why?
<!doctype html> <html> <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> <body> <div ng-app="myapp" ng-controller="customersctrl"> <table> <tr ng-repeat="x in names"> <td onclick="dum();">{{ x.name }}</td> <td>{{ x.country }}</td> </tr> </table> </div> <script> var app = angular.module('myapp', []); app.controller('customersctrl', function($scope, $http) { $http.get("http://www.w3schools.com/angular/customers.php") .success(function (response) {$scope.names = response.records;}); $scope.dum = function() { alert("hi you"); } }); </script> </body> </html>
javascript onclick
event binding work, not have function named dum
in global scope.
it work if in html, for example:
<script> function dum(){ alert('test') } </script>
in angular world need use ng-click
instead, bound function expression evaluated against scope
. ng-click
built-in directive binds click event internally , performs digest cycle after evaluating function expression bound it. example
Comments
Post a Comment