How to execute AngularJS controller function on page load?

前端 未结 14 2531
一整个雨季
一整个雨季 2020-11-22 16:04

Currently I have an Angular.js page that allows searching and displays results. User clicks on a search result, then clicks back button. I want the search results to be disp

14条回答
  •  借酒劲吻你
    2020-11-22 16:25

    Dimitri's/Mark's solution didn't work for me but using the $timeout function seems to work well to ensure your code only runs after the markup is rendered.

    # Your controller, including $timeout
    
    var $scope.init = function(){
     //your code
    }
    
    $timeout($scope.init)
    

    Hope it helps.

提交回复
热议问题