如何在准备好文档的AngularJS控制器中运行函数?

我在我的角度控制器中有一个函数,我希望可以在准备好文档的文件上运行此函数,但是我注意到在创建dom时,它会运行角度函数。


 function myController($scope)

 {

     $scope.init = function()

     {

        // I'd like to run this on document ready

     }


     $scope.init(); // doesn't work, loads my init before the page has completely loaded

 }

有人知道我该怎么做吗?


慕标5832272
浏览 523回答 3
3回答

开满天机

快速查找:// register controller in html<div data-ng-controller="myCtrl" data-ng-init="init()"></div>// in controller$scope.init = function () {&nbsp; &nbsp; // check if there is query in url&nbsp; &nbsp; // and fire search in case its value is not empty};这样,您不必等到文档准备就绪。
打开App,查看更多内容
随时随地看视频慕课网APP