2

I am not sure why but I am trying to make an image button and the URL's come from getting a JSON object in my controller, but what ever the link is through an error, and if I change it to works fine!!!

Controller:

$scope.iconImage = 'http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png';

HTML:

<!-- Error: [$sce:insecurl] Blocked loading resource from url not allowed by $sceDelegate policy. -->
<input type="image" ng-src="{{iconImage}}" />

<!-- This works fine -->
<img ng-src="{{iconImage}}" />

2 Answers 2

3

You might use the Strict Contextual Escaping (SCE) mode to marked the URL as a safe content source.

See trustAsResourceUrl(value);

Inject [$sce] in your controller and then use it like this:

$scope.iconImage = $sce.trustAsResourceUrl('http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png');
Sign up to request clarification or add additional context in comments.

1 Comment

That's right. Just to add that using ngSrc for img tag is an exception from Strict Contextual Escaping, that's why it works for <img ng-src="{{iconImage}}" />.
0

You can white list the URL using the $sceDelegateProvider. See here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.