Reputation: 3246
In my template I have something like the following:
<img data-ng-if="$ctrl.shouldShowFacebookPixel"
src="https://www.facebook.com/tr?id={{$ctrl.facebookPixelId}}&ev=PageView"
/>
When I load the page I can see in my dev tools a request is made to
https://www.facebook.com/tr?id={{$ctrl.facebookPixelId}}&ev=PageView
Then a bit later a request is made to the correct URL after the variable has been substituted.
https://www.facebook.com/tr?id=blah&ev=PageView
How can I stop the initial request before variable substitution has happened?
Upvotes: 0
Views: 24
Reputation: 77904
Go for ng-src
instead src
:
<img data-ng-if="$ctrl.shouldShowFacebookPixel"
ng-src="{{'https://www.facebook.com/tr?id='+ $ctrl.facebookPixelId + '&ev=PageView'}}"
/>
Angular needs to compile the URL, and your browser has no clue what is {{/* ... */}}
. This is a reason why you see
https://www.facebook.com/tr?id={{$ctrl.facebookPixelId}}&ev=PageView
Upvotes: 2