为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕标5832272 2019-10-14 14:33:16
我在我的角度控制器中有一个函数,我希望可以在准备好文档的文件上运行此函数,但是我注意到在创建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 }有人知道我该怎么做吗?
查看完整描述

3 回答

?
开满天机

TA贡献1786条经验 获得超12个赞

快速查找:


// register controller in html

<div data-ng-controller="myCtrl" data-ng-init="init()"></div>


// in controller

$scope.init = function () {

    // check if there is query in url

    // and fire search in case its value is not empty

};

这样,您不必等到文档准备就绪。


查看完整回答
反对 回复 2019-10-14
  • 3 回答
  • 0 关注
  • 517 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信