0

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/)

4
  • which datepicker you are using? Commented Jan 19, 2015 at 4:06
  • in the controller you can reinitialized but not a good practice. Commented Jan 19, 2015 at 4:07
  • I use the bootstrap datetimepicker Commented Jan 19, 2015 at 4:28
  • use angular bootstrap as it's very easy to configure angular-ui.github.io/bootstrap/#/datepicker Commented Jan 19, 2015 at 6:09

2 Answers 2

2

Just use the $viewContentLoaded event

$scope.$on('$viewContentLoaded', function() {
    //call it here
    yourFunction();
});
Sign up to request clarification or add additional context in comments.

1 Comment

It should be noted that this code should be placed into a directive and not called from a controller or a service \ etc. As the intent is to do DOM manipulation.
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.