1

Hi How to run jquery scripts when I load data in ng-repeat. jquery works good when I have a static dom element, but when I use ng-repeat scripts not working I need to use dynamically height of div, and bootstrap tooltip. I have this code:

$(document).ready(function () {
    //myMovies
        //$('.templates_movies').height($('.templates').outerHeight());
    $(document).on("load", ".templates_movies", function() {
        $('[data-toggle="tooltip"]').tooltip();
    });


});

But it's not working. Please help me.

1
  • 1
    you have to create a directive for that Commented Dec 16, 2016 at 12:57

2 Answers 2

1

you can create directive

app.directive("tooltip",function(){
  return{
    link: function(scope,ele,attr){
      $('[data-toggle="tooltip"]').tooltip(); 
    }
  }
});

and then use "tooltip" with your ng-repeat like

<div ng-repeat ="item in [1,2,3]" tooltip>
   <span data-toggle="tooltip"  class="test" title="Hiiii" ng-bind="item"></span>
</div>
Sign up to request clarification or add additional context in comments.

3 Comments

i include: <script src="js/jquery-3.1.1.min.js"></script> <script src="bootstrap/js/bootstrap.min.js"></script>
i do that i have first app.controller(...).directive()
Try my new updated code under directive link function "$('[data-toggle="tooltip"]').tooltip(); ". I think it will work.
0

An example of the link function of the directive would be:

function link (scope, element) {
  $(element[0].querySelectorAll('[data-toggle="tooltip"]')).tooltip();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.