window.onload does not work in AngularJS
问题 This code in a simple HTML file works: <script> function load() { alert("load event detected!"); } window.onload = load; </script> However, if I put it into the index.html file of an AngularJS web app, it does not. Does anybody know why not? 回答1: Call your function with ng-init var app = angular.module('app',[]); app.controller('myController', function($scope){ $scope.load = function () { alert("load event detected!"); } }); <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23