AngularJs pass value to ng-click function
home
Run
screen_rotation
fullscreen
cloud_download
<!DOCTYPE html> <html lang="en"> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script> <script> var myApp = angular.module("myApp", []); myApp.controller("myController", function($scope) { $scope.message = ''; $scope.rows = [{'id':11, 'name':'John'}, {'id':10, 'name':'Kelly'}, {'id':139, 'name':'Rimmy'}, {'id':101, 'name':'Kat'}, {'id':122, 'name':'Yesha'}, {'id':134, 'name':'Robert'}]; $scope.removeRow = function(index, id) { if(index != -1){ $scope.rows.splice(index,1); $scope.message = "User with id "+id+' removed successfully.'; // do other stuffs such as perform ajax request if want to delete data from //server } }; }); </script> </head> <body> <div ng-app="myApp"> <div ng-controller="myController"> <span style='color:green;font-weight:bold;'>{{message}}</span> <table> <tr><th>Id</th><th>Name</th></tr> <tr ng-repeat="content in rows"> <td>{{content.id}}</td> <td>{{content.name}}</td> <td><a href="#" ng-click="removeRow($index, content.id)">Remove</a></td> </tr> </table> </div> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script> <script> var myApp = angular.module("myApp", []); myApp.controller("myController", function($scope) { $scope.message = ''; $scope.rows = [{'id':11, 'name':'John'}, {'id':10, 'name':'Kelly'}, {'id':139, 'name':'Rimmy'}, {'id':101, 'name':'Kat'}, {'id':122, 'name':'Yesha'}, {'id':134, 'name':'Robert'}]; $scope.removeRow = function(index, id) { if(index != -1){ $scope.rows.splice(index,1); $scope.message = "User with id "+id+' removed successfully.'; // do other stuffs such as perform ajax request if want to delete data from //server } }; }); </script> </head> <body> <div ng-app="myApp"> <div ng-controller="myController"> <span style='color:green;font-weight:bold;'>{{message}}</span> <table> <tr><th>Id</th><th>Name</th></tr> <tr ng-repeat="content in rows"> <td>{{content.id}}</td> <td>{{content.name}}</td> <td><a href="#" ng-click="removeRow($index, content.id)">Remove</a></td> </tr> </table> </div> </div> </body> </html>
Copyrights@tutorialsplane.com