user1455719
user1455719

Reputation: 1065

How to call a javascript function after the angularjs has finished loading and page is rendered

Background:

I have an angularjs application which displays a datetimepicker field.

Issue:

Once the page is loaded I want to run a javascript function to initialize the datepicker used in the page. At the moment it seems that the function call that I placed at the end of the page doesn't get picked.

Note : I use the 'bootstrap datetimepicker' from (http://eonasdan.github.io/bootstrap-datetimepicker/)

Upvotes: 0

Views: 1084

Answers (2)

Enzey
Enzey

Reputation: 5254

The only way to know when Angular is done is from inside Angular. You should wrap the code that initalizes the date picker into a directive, add binding as needed, and in a $timeout function do the JS initialization.

Upvotes: 0

Felix D.
Felix D.

Reputation: 2220

Just use the $viewContentLoaded event

$scope.$on('$viewContentLoaded', function() {
    //call it here
    yourFunction();
});

Upvotes: 2

Related Questions