Search code examples
javascriptangularjsangularjs-ng-include

ng-include rendering before src is set


I'm trying to find a way that the directive ng-include is not trying to render before a value on scope is set. Is that possible?

Here is the example:

<ng-include src="'./lib/templates/' + $parent.currentEditable.editTemplate"></ng-include>

I think angular is trying to render that before $parent.currentEditable.editTemplate is defined. In the console I get:

GET http://localhost:3000/admin/lib/templates/ 404 (Not Found)

Solution

  • Use ng-if to hold off rendering til src is set

    <ng-include ng-if="$parent.currentEditable.editTemplate" src="'./lib/templates/' + $parent.currentEditable.editTemplate"></ng-include>