Accustomed to Window.onload (), $ (document). Ready (), now replaced by something else, really a bit unaccustomed. Here are some of the 4 things that are commonly used.
Write directly in 1,html
The code is as follows |
|
<script src= "Lib/angular/angular.min.js" type= "Text/javascript" ></script> <script type= "Text/javascript" > Angular.element (window). bind (' Load ', function () { Alert (' 1 '); }); Alert (' 2 '); </script> |
Not recommended, directly inside the template, write JS code.
2, using $on or $watch in controller.
The code is as follows |
|
Bookcontrollers.controller (' bookctrl_test ', [' $scope ', ' $routeParams ', function ($scope, $routeParams) { $scope. $on (' $viewContentLoaded ', function () { Alert (' 1 '); }); Alert (' 2 '); }]); Bookcontrollers.controller (' Bookctrl_test1 ', [' $scope ', ' $routeParams ', function ($scope, $routeParams) { $scope. $watch (' $viewContentLoaded ', function () { Alert (' 1 '); }); Alert (' 2 '); }]); |
3, using Data-ng-init
The code is as follows |
|
<div ng-controller= "Test" > <div data-ng-init= "Load ()" ></div> </div> |
Note: Data-ng-init in controller.
code is as follows |
|
& nbsp; bookcontrollers.controller (' Testinit ', [' $scope ', ' $routeParams ', function ($scope, $routeParams) { $scope. Load = function () { alert (' Code here '); } }]; |