0

i'm trying to write an AngularJS Directive that checks if a URL exist, if it does then it will display the image. Otherwise it will return nothing or a blank tag. Any advice would be appreciated, here's the fiddle I have so far, can't seem to get it to even read the url being passed in. http://jsfiddle.net/stevenng/dXeap/8/

1 Answer 1

1

You will only be able to this with images on the same domain as it would violate cross-domain policy otherwise. If that is still ok then it should be possible by using AJAX to do a HEAD request and checking the HTTP status (e.g. 404) of the response.

I fixed up your code a bit so that it works. http://jsfiddle.net/LwpEP/1/ See how you get on from that starting point and come back here if you run into more issues.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Daveyjoe, I was ultimately trying to create a directive for a presence indicator, so the data passed in would be like "online", "offline", "away". So my directive will display a red, yellow, or green image. Could you do a jsfiddle example of that? :)
This doesn't seem to relate to your original question. If this is a new question then perhaps it would make more sense to create a new question on StackOverflow.

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.