- Slider
npm install hammerjs --save
//.angular-cli.json
"scripts": [
"../node_modules/hammerjs/hammer.min.js"
]
//app.module.ts
import {SliderModule} from './slider/slider.module';
...
imports: [
...,
SliderModule
],
- Install dependencies
npm install hammerjs --save
DON'T forget to import to angular-cli:
//.angular-cli.json
"scripts": [
"../node_modules/hammerjs/hammer.min.js"
]
-
Copy slider component to your project
-
Import slider to app module
//app.module.ts
import { SliderComponent } from './slider/slider.component';
- Import HammerJs for touch actions
//app.module.ts
import { HammerGestureConfig, HAMMER_GESTURE_CONFIG} from '@angular/platform-browser';
- Import Angular animations
//app.module.ts
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
- Add declaration to handle HammerJs scroll event
//app.module.ts
declare var Hammer: any;
export class MyHammerConfig extends HammerGestureConfig {
buildHammer(element: HTMLElement) {
const mc = new Hammer(element, {
touchAction: 'pan-y'
});
return mc;
}
}
- Add HammerJS to providers
//app.module.ts
{
provide: HAMMER_GESTURE_CONFIG,
useClass: MyHammerConfig
}
//app.module.ts
// slider - BEGIN
import { SliderComponent } from './slider/slider.component';
import { HammerGestureConfig, HAMMER_GESTURE_CONFIG} from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
// slider - END
declare var Hammer: any;
export class MyHammerConfig extends HammerGestureConfig {
buildHammer(element: HTMLElement) {
const mc = new Hammer(element, {
touchAction: 'pan-y'
});
return mc;
}
}
@NgModule({
declarations: [
AppComponent,
SliderComponent
],
imports: [
BrowserModule,
HttpClientModule,
BrowserAnimationsModule
],
providers: [
LocalDataService,
{
provide: HAMMER_GESTURE_CONFIG,
useClass: MyHammerConfig
}],
bootstrap: [AppComponent]
})
export class AppModule { }
- Add slider component
<mk-slider [config]="slideConfig" [slides]="slides"></mk-slider>
- Format data before passing to slider component. Example of expected data format:
{
"id": 1,
"image": "https://images.pexels.com/photos/462235/pexels-photo-462235.jpeg?h=350&auto=compress&cs=tinysrgb",
"thumbnail": "https://images.pexels.com/photos/462235/pexels-photo-462235.jpeg?h=350&auto=compress&cs=tinysrgb",
"title": "Slider 3",
"description": "Short text"
},
{
"id": 2,
"image": "https://images.pexels.com/photos/301643/pexels-photo-301643.jpeg?w=940&h=650&auto=compress&cs=tinysrgb",
"thumbnail": "https://images.pexels.com/photos/301643/pexels-photo-301643.jpeg?w=940&h=650&auto=compress&cs=tinysrgb",
"title": "Slider 4",
"description": "Short text 4"
}
This project was generated with Angular CLI version 1.7.0.
Run ng serve
for a dev server. Navigate to http://localhost:4200/
. The app will automatically reload if you change any of the source files.
Run ng generate component component-name
to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module
.
Run ng build
to build the project. The build artifacts will be stored in the dist/
directory. Use the -prod
flag for a production build.
Run ng test
to execute the unit tests via Karma.
Run ng e2e
to execute the end-to-end tests via Protractor.
To get more help on the Angular CLI use ng help
or go check out the Angular CLI README.