sharataka sharataka - 1 year ago 50
Javascript Question

How to prefetch an image in AngularJS?

I am trying to prefetch an image in my Angular app that sits within a Chrome plugin.

In the controller, I have:

$scope.nextlocation = '';

In my view, I have:

<link rel="prefetch" href="{{nextlocation}}">

When I load the page, I get an error saying:

GET chrome-extension://jlkgcdcdoooiaeamkhagpdolhgjgfgem/%7B%7Bnextlocation%7D%7D net::ERR_FILE_NOT_FOUND

When I hardcord the image in the doc, like below, it works fine.

<link rel="prefetch" href="">

How do I get this to work so that it dynamically updates?

<link rel="prefetch" href="">

Change the above to:

<link rel="prefetch" ng-href="{{nextlocation}}">