I didn't get clarity on 'ngSrcset', when i have gone through the Angular API reference docs. Can someone clarify with an example.
https://docs.angularjs.org/api/ng/directive/ngSrcset
Probably the easiest way to understand it is to analyze what happens when the page loads in each case.
<img srcset="http://www.gravatar.com/avatar/{{hash}} 2x"/>`
Here is what happens:
srcset found and recognizedhttp://www.gravatar.com/avatar/{{hash}}, which doesn't exist, of course, so we get a 404http://www.gravatar.com/avatar/realHash, which is what we needed<img ng-srcset="http://www.gravatar.com/avatar/{{hash}} 2x"/>`
Here is what happens:
ng-srcset attribute is found, but not recognized, so no server calls are madesrcset attribute is created from the interpolated value of ng-srcset so we instantly get something like: <img ng-srcset="http://www.gravatar.com/avatar/{{hash}} 2x" srcset= "http://www.gravatar.com/avatar/realHash 2x" />, which is exactly what we want. srcset attribute is found and recognized, so the server make a call to http://www.gravatar.com/avatar/realHash, and all is goodThe same principle works for ng-src, ng-href, etc.
Here's an interesting article about the scrset itself: http://www.smashingmagazine.com/2013/08/21/webkit-implements-srcset-and-why-its-a-good-thing/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With