<div ng-app="myapp" ng-controller="mycontroller as ctrl"> <table border="1"> <tr><td>id</td><td>$$hashKey</td></tr> <tr ng-repeat="n in ctrl.note"> <td ng-bind="n.id"></td><td ng-bind="n.$$hashKey"></td> </tr> </table> <input type="button" ng-click="ctrl.delete()" value="刪除最後一筆" /> <input type="button" ng-click="ctrl.reload()" value="重新取得" /> </div>
angular.module("myapp",[]).controller("mycontroller",[function(){ var self = this; function getnote() { var note = [ { id: 1 }, { id: 2 }, { id: 3 }, { id: 4 } ] return note; } self.note = getnote(); //重新取得 self.reload = function() { self.note = getnote(); } //刪除最後一筆 self.delete = function() { $("table tr:last").remove(); } }]);