Angular bindings for Synaps.Pics
With npm:
npm i --save ngx-synaps-pics
With yarn:
yarn add ngx-synaps-pics
Import SynapsPicsModule
to your app.
import { SynapsPicsModule } from 'ngx-synaps-pics';
@NgModule{
....
imports: [
...,
SynapsPicsModule
],
Now you can use synapsPics
directive in your templates.
<img [synapsPics]="imageUrl" width="100" height="100" crop="fill">
By default, synapsPics
directive sets the image url for src
and/or srcset
attribute. If you want to use image as a background you can use as-background
attribute.
<div [synapsPics]="imageUrl" width="100" height="100" as-background></div>
You can also set url as an attribute:
<a [synapsPics]="imageUrl" width="100" height="100" crop="fill" as-attr="href">Link to image</a>
ngx-synaps-pics
has the ability lazy loading images with a given condition or by checking if it's in the viewport.
<img [synapsPics]="imageUrl" lazy>
Please note that, visibility checking is using Intersection Observer API. If you need to support Internet Explorer and Safari browsers please include intersection observer pollyfill to your page. Just run
npm i --save intersection-observer
and then addimport 'intersection-observer';
line to yourpollyfill.ts
file.
[lazy]
attribute also accepts a boolean value. So you can write some conditions for defining when image will be loaded. This feature is handy when you want to use it with a slider/carousel component for example.
<div class="slide" *ngFor="let slide of slides; let i = index">
<img [synapsPics]="imageUrl" [lazy]="activeSlide === i">
</div>
For the original image below available manipulation parameters and example results are here.
Special thanks to BrowserStack for their support about testing our work on multiple platforms.