Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hugojosefson/image-url-for-angular

AngularJS directive for validating and figuring out width/height from an image url.
https://github.com/hugojosefson/image-url-for-angular

Last synced: 29 days ago
JSON representation

AngularJS directive for validating and figuring out width/height from an image url.

Awesome Lists containing this project

README

        

# image-url-for-angular

AngularJS directive for validating and figuring out width/height from an image url.

## Installation

### As a [component](https://github.com/component/component)

$ component install hugojosefson/[email protected]

In JS, to let it register its AngularJS module:

require("image-url-for-angular");

### With [Bower](http://bower.io/)

$ bower install hugojosefson-image-url-for-angular

In HTML:

### Old-school

$ wget https://raw.github.com/hugojosefson/image-url-for-angular/0.0.4/index.js -O image-url-for-angular-0.0.4.js

In HTML:

## API

One directive is registered, `imageUrl`, which you use like this:

...

Then the following are automatically kept up-to-date in the `$scope`:

myForm.screenshotUrl.$valid
myForm.screenshotUrl.$invalid
screenshot.width
screenshot.height

The attributes `image-url-width-model` and `image-url-height-model` are each optional, but if
any of them is specified, the directive will keep the corresponding scope variable updated with the width/height.

In case of an error, for example if the url is incorrect, or the image loaded is not a valid image, width and height
models are set to `null` and the form field's validity is set to invalid (specified as
`imageUrl`.)

### Avoiding integration with form validity

If the url should not be part of the validity checking of its form (and by extension its parent form), use can specify
the attribute `image-url-integrate-with-form-validity="false"` on the `` tag. Then it will not set `$valid` nor
`$invalid`.

For most cases you can check for a valid image by checking the width and/or height models instead, if you expect images
to be > 0 pixels.

## License

MIT