AngularJS加载完成之后触发事件

前端之家收集整理的这篇文章主要介绍了AngularJS加载完成之后触发事件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. @{
  2. Layout = null;
  3. }
  4. <!DOCTYPE html>
  5. <html ng-app="my_app">
  6. <head>
  7. <Meta name="viewport" content="width=device-width" />
  8. <title>Index</title>
  9. <script src="~/Scripts/jquery-1.10.2.min.js"></script>
  10. <script src="~/Scripts/angular.min.js"></script>
  11. <script type="text/javascript">
  12. var app = angular.module("my_app",[]);
  13. app.controller('my_controller',function ($scope) {
  14. $scope.students = [
  15. { id: 1,name: '张一' },{ id: 2,name: '李二' },{ id: 3,name: '王三' },{ id: 4,name: '马四' },{ id: 5,name: '鬼五' }
  16. ];
  17. $scope.getStudent = function (id) {
  18. alert(id);
  19. }
  20. });
  21. app.run(function ($timeout) {//等待AngularJS加载完成之后触发事件
  22. var a = $timeout(function () {
  23. alert($('table tr').length);
  24. },1000);
  25. });
  26. </script>
  27. </head>
  28. <body ng-controller="my_controller">
  29. <table>
  30. <tr>
  31. <th>id</th>
  32. <th>name</th>
  33. </tr>
  34. <tr ng-repeat="item in students">
  35. <td>{{item.id}}</td>
  36. <td><a href="#" ng-click="getStudent(item.id);">{{item.name}}</a></td>
  37. </tr>
  38. </table>
  39. </body>
  40. </html>

猜你在找的Angularjs相关文章