0

I am having strange experience while using ng-include. I am trying to get template path by triggering a function defined in controller which is returning path as per parameter passed. Here is my code-

<tr ng-repeat="detail in Ctrl.details" ng-include="Ctrl.getTemplate(object)"></tr>

Contoller-

self.getTemplate = function (obj) {
    if (<condition>) {
        return 'view1';
    } else return 'view2';
};

This is working really fine, but I observed really strange behavior while debugging the code. In my table row I am having 3 buttons and I applied Bootstrap tooltip on them. Whenever I hover them tooltip comes up & on mouse left getTemplate() gets called. Do anybody know why this is happening?

2
  • Angularjs does checks on ng-include , ng-model fields etc... each time it thinks the value may have changed. The best is to store the url in an object, so the function will not be called 50 times (for example object.__url). Commented Feb 17, 2016 at 9:41
  • Also please note that ng-include is deprecated in angular 2. Commented Feb 17, 2016 at 9:59

1 Answer 1

1

This is expected behaviour.

Have a look at this article. Angular needs to check whether the expression for ng-include has changed or not. In order to do that it needs to evaluate Ctrl.getTemplate(object) on every digest loop because there's no other way to find out whether its return value has changed and therefore it needs to pass a new value to ng-include.

Sign up to request clarification or add additional context in comments.

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.