0

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";

2 Answers2

1

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.

Starscream1984
  • 3,072
  • 1
  • 19
  • 27
  • Slow in what way? When requesting the html fragment? – Starscream1984 Nov 25 '15 at 14:35
  • yes, it is a delay here, it takes more than 1 second. –  Nov 25 '15 at 15:08
  • Don't think it's anything to with `ng-include` , I use it all over the place and there's no delay, the fragments come back from the server fast and are rendered almost immediately. Seems like maybe an issue with the server, if you look at the network tab in Chrome Dev Tools as the page loads, you can see when each http request is fired, and how long it takes to get back a response. – Starscream1984 Nov 25 '15 at 15:17
0

Try this way : <ng-include src="{{ content.src }}"/>

Something like this should be working as well: ng-include with a variable for src

Havent tested yet, if not working, please make a plunker for easy helping

Edit:

<ng-include src="content.src"/> is the way to go

Community
  • 1
  • 1
  • it does also not work: `Error: [$parse:syntax] Syntax Error: Token '{' invalid key at column 2 of the expression [{{ content.src }}] starting at [{ content.src }}].` –  Nov 25 '15 at 14:06
  • https://www.reddit.com/r/angularjs/comments/326det/how_do_i_use_nginclude_with_a_variable_in_src/ According to this article: remove the {{}} signs. Still could not test that – Ágoston Székely Nov 25 '15 at 14:10
  • ``helps, thank you. Would you update your answer, so that I can mark it as correct answer? –  Nov 25 '15 at 14:32
  • Someone else was faster.. :/ –  Nov 25 '15 at 14:33