项目作者: prasenjitjsr

项目描述 :
Angular 2/5 Image slider
高级语言: TypeScript
项目地址: git://github.com/prasenjitjsr/angular2-5-image-slider-image-gallary.git


Angular 2/5 Image-slider or image-gallary

capture

Angular Image slider used Angular-CLI.
I have created a gallary directive which accept some gallary configuration via attribute.

You can just add directive file in your project and use the below code in Template file:

Directive name: ‘gallarySlide’

BreakPoint: using ‘item-md=4’ ‘item-sm=2’ ‘item-xs’ attribute

.html file:

  1. <div class="row">
  2. <div class="gallary-wrap" gallarySlide="item" gallaryBoxID="items"
  3. item-md=4 item-sm=2 item-xs=1>
  4. <div class="items" id="items">
  5. <div *ngFor="let image of gallaryimage" class="item">
  6. <a href="https://www.onwebg.com/" target="_blank">
  7. <img src="assets/images/{{image.image}}" alt="{{ image.title }}">
  8. </a>
  9. </div>
  10. </div>
  11. <div class="slider-controller">
  12. <button class="prevbtn slideBtn">Prev</button>
  13. <button class="nextbtn slideBtn">next</button>
  14. </div>
  15. </div>
  16. </div>

.ts file

  1. import { Component, OnInit } from '@angular/core';
  2. import { GallaryService } from './gallary.service'
  3. @Component({
  4. selector: 'app-root',
  5. templateUrl: './app.component.html',
  6. styleUrls: ['./app.component.css']
  7. })
  8. export class AppComponent implements OnInit {
  9. activeUsers:String[];
  10. inactiveUsers:String[];
  11. gallaryimage:object;
  12. constructor(private gallaryservice:GallaryService){
  13. }
  14. ngOnInit() {
  15. this.gallaryimage=this.gallaryservice.images;
  16. }
  17. }

.css file

use gallary css using Flex-layout (Css code in app.component.css)

hammerJs

I used hammerJs for swipe event which make slider mobile friendly as well.

  1. npm i hammerjs --save

and add js file to .angular-cli.json file:

  1. "scripts": [
  2. "../node_modules/hammerjs/hammer.min.js"
  3. ],

This project was generated with Angular CLI version 1.5.0.

Development server

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.

Code scaffolding

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.

Build

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.

Running unit tests

Run ng test to execute the unit tests via Karma.

Running end-to-end tests

Run ng e2e to execute the end-to-end tests via Protractor.

Further help

To get more help on the Angular CLI use ng help or go check out the Angular CLI README.