AngularJS: callback after render (work with DOM after render)

前端 未结 5 836
长发绾君心
长发绾君心 2020-12-08 02:26

How can run a method $scope.myWork() after render template? I want to set the $scope.value and after that I need to change something with JQuery (e

5条回答
  •  暖寄归人
    2020-12-08 03:01

    I found this page when looking for a way to profile DOM rendering. I found a far simple solution which is working for my use case.

    Attach an ng-init handler to the DOM element and in the handler function, use $timeout to yield execution. Example:

    HTML:

    JS:

    $scope.foo = function() {
        $timeout(function() {
            // This code runs after the DOM renders
        });
    });
    

提交回复
热议问题