sharataka sharataka - 1 year ago 82
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?

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

Change the above to:

<link rel="prefetch" ng-href="{{nextlocation}}">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download