Search code examples
angularjsangularjs-ng-include

Fill the src attribute of ng-iclude with data from model


Why do I get the error message:

Error: [$interpolate:noconcat] Error while interpolating: '{{ content.src }}'
Strict Contextual Escaping disallows interpolations that concatenate multiple expressions when a trusted value is required.

with this syntax:

<div id="content" class="content">
     <ng-include src="'{{ content.src }}'"/>
</div>

And the model is

$scope.content = {};
$scope.content.src = "content.html";

Solution

  • I have done this in some of my projects with syntax like:

    <ng-include src="content.src"/>
    

    The src attribute doesn't need the bracket notation, you can just reference scope variables. Single quotes are needed only if you are using a string literal.