1

I have this template

<script type="text/ng-template" id="template">
    <span class="count-container">
        <span >{{count}}</span>
    </span>
</script>

and I am including this multiple times with different ng-init like this

<span ng-include="'template'" ng-init="count=$ctrl.getTotalCount()"></span>

<span ng-include="'template'" ng-init="count=$ctrl.tabs[0].errorCount"></span>

this works fine on the very first load, but when the values are updated in the component, those are not reflected where the template is loaded. I guess it's due to how the ng-init works since it's everything fine on the 1st load.

So what should be used so that the values are updated in the template?

6
  • Where is count being defined? Is it within or outside the loop of the template? Commented Mar 4, 2019 at 9:30
  • count is in template. how do i update it from controller, can you please give an example. how can i use ngModel for it? Commented Mar 4, 2019 at 9:35
  • @BhojendraRauniyar I'm not sure if setting an ng-model to span would work. Commented Mar 4, 2019 at 9:39
  • @AmarKoli It will not be clear what is wrong until you show the controller code. Commented Mar 4, 2019 at 9:40
  • I don't think you need to even use ng-init with ng-template. That should be done with your ng-controller. Commented Mar 4, 2019 at 9:50

1 Answer 1

1

You can use $watch:

ng-init="$watch('count=$ctrl.tabs[0].errorCount')"

This is just an inline solution. However, you should use scope.$watch().

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

1 Comment

let me try this

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.