Search code examples
angularjsangular-promiseangularjs-ng-includeangular-http

Update variable inside ng-include template once a promise is kept


I'm in an interesting conundrum.

In my app, I am using a recursive <script> which is referred to in my main page via an ng-include:

<div ng-include="'theTemplate.html'" onload="one=features.items.one"></div>

The data for features.items.one is loaded via external api using $http and is set when the $http promise is kept.

The problem is, that the ng-include loads before the promise is kept, and when the promise does complete, the {{one}} INSIDE the script does not update (because ng-include creates a new scope)

How can I get the variable inside the script to update when the promise completes?


Solution

  • Extending my comment:

    <div ng-if="your condition">
    <div ng-include="'theTemplate.html'" onload="one=features.items.one"></div>
    </div>