Skip to content

Commit 65ef06a

Browse files
committed
added new service for reset and moveToSlide functionality
1 parent c5d83a9 commit 65ef06a

File tree

10 files changed

+497
-137
lines changed

10 files changed

+497
-137
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ dist
77

88
# OS generated files
99
Thumbs.db
10-
.DS_Store
10+
.DS_Store
11+
.vscode

README.md

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export class SampleComponent implements OnInit {
103103
export class NguCarouselStore {
104104
type: string;
105105
deviceType: DeviceType;
106-
classText: string;
106+
token: string;
107107
items: number;
108108
load: number;
109109
deviceWidth: number;
@@ -206,18 +206,30 @@ This is HTML I'm using in the carousel. Add your own css according to this eleme
206206

207207
<ngu-carousel
208208
[inputs]="carouselBanner"
209-
[moveToSlide]="2"
209+
(initData)="initDataFn($event)"
210210
(onMove)="onmoveFn($event)"
211211
(carouselLoad)="loadItemsFn()">
212212
</ngu-carousel>
213213

214214
```
215215

216216
* `inputs` is an `Input` and It accepts `NguCarousel`.
217-
* `moveToSlide` is an `Input` which accepts point numbers. Numbers represents no of slide to be done.
217+
* `initData` is an `Output` which triggered on carousel init and it emits token to exchange with service to contol the carousel.
218218
* `onMove` is an `Output` which triggered on every slide before start and it will emit `$event` as `NguCarouselStore` object.
219219
* `carouselLoad` is an `Output` which triggered when slide reaches the end on items based on inputs `load`.
220220

221+
222+
##Carousel Service
223+
224+
```javascript
225+
import { NguCarouselService } from '@ngu/carousel';
226+
```
227+
This carousel Service supports:
228+
229+
* `reset(token)` - This function will reset the carousel
230+
* `moveToSlide(token, index, animate)` - This function is used to move to index with animation control.
231+
232+
221233
# Getstarted guide
222234

223235
## Banner with Custom point style
@@ -231,7 +243,6 @@ import { NguCarousel, NguCarouselStore } from '@ngu/carousel';
231243
template: `
232244
<ngu-carousel
233245
[inputs]="carouselBanner"
234-
[moveToSlide]="1"
235246
(onMove)="onmoveFn($event)">
236247
237248
<ngu-item NguCarouselItem class="bannerStyle">
@@ -337,17 +348,18 @@ export class Sample implements OnInit {
337348

338349
```
339350

340-
## Tile
351+
## Tile with Service
341352

342353
```javascript
343354
import { Component } from '@angular/core';
344-
import { NguCarousel } from '@ngu/carousel';
355+
import { NguCarousel, NguCarouselStore, NguCarouselService } from '@ngu/carousel';
345356

346357
@Component({
347358
selector: 'app-carousel',
348359
template: `
349360
<ngu-carousel
350361
[inputs]="carouselTile"
362+
(initData)="initDataFn($event)"
351363
(carouselLoad)="carouselTileLoad($event)">
352364
353365
<ngu-tile NguCarouselItem *ngFor="let Tile of carouselTileItems">
@@ -357,6 +369,7 @@ import { NguCarousel } from '@ngu/carousel';
357369
<button NguCarouselPrev class='leftRs'>&lt;</button>
358370
<button NguCarouselNext class='rightRs'>&gt;</button>
359371
</ngu-carousel>
372+
<button (click)="resetFn()">Reset</button>
360373
`,
361374
styles: [`
362375
@@ -392,10 +405,13 @@ import { NguCarousel } from '@ngu/carousel';
392405
`]
393406
})
394407
export class Sample implements OnInit {
408+
private carouselToken: string;
395409

396410
public carouselTileItems: Array<any>;
397411
public carouselTile: NguCarousel;
398412

413+
constructor(private carousel: NguCarouselService) { }
414+
399415
ngOnInit(){
400416
this.carouselTileItems = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
401417

@@ -413,6 +429,18 @@ export class Sample implements OnInit {
413429
}
414430
}
415431

432+
initDataFn(key: NguCarouselStore) {
433+
this.carouselToken = key.token;
434+
}
435+
436+
resetFn() {
437+
this.carousel.reset(this.carouselToken);
438+
}
439+
440+
moveToSlide() {
441+
this.carousel.moveToSlide(this.carouselToken, 2, false);
442+
}
443+
416444
public carouselTileLoad(evt: any) {
417445

418446
const len = this.carouselTileItems.length

index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { NguCarouselModule } from './src/ngu-carousel.module';
2-
export { NguCarousel, NguCarouselStore } from './src/ngu-carousel/ngu-carousel.interface';
2+
export { NguCarousel, NguCarouselStore } from './src/ngu-carousel/ngu-carousel.interface';
3+
export { NguCarouselService } from './src/ngu-carousel.service';

package-lock.json

Lines changed: 211 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngu-carousel",
3-
"version": "1.4.2",
3+
"version": "1.4.5",
44
"description": "Angular Universal carousel",
55
"scripts": {
66
"transpile": "ngc ",
@@ -29,4 +29,4 @@
2929
"@angular/core": ">=4.0.0",
3030
"@angular/platform-browser": ">=4.0.0"
3131
}
32-
}
32+
}

rollup.config.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
export default {
2-
entry: 'dist/index.js',
3-
dest: 'dist/bundles/ngucarousel.umd.js',
4-
sourceMap: false,
5-
format: 'umd',
6-
moduleName: 'ng.ngucarousel',
7-
external: ['@angular/core', '@angular/common', '@angular/platform-browser'],
8-
globals: {
9-
'@angular/core': 'ng.core',
10-
'@angular/common': 'ng.common',
11-
'@angular/platform-browser': 'ng.platform-browser',
12-
'rxjs/Observable': 'Rx',
13-
'rxjs/ReplaySubject': 'Rx',
14-
'rxjs/add/operator/map': 'Rx.Observable.prototype',
15-
'rxjs/add/operator/mergeMap': 'Rx.Observable.prototype',
16-
'rxjs/add/observable/fromEvent': 'Rx.Observable',
17-
'rxjs/add/observable/of': 'Rx.Observable'
18-
}
19-
}
2+
entry: 'dist/index.js',
3+
dest: 'dist/bundles/ngucarousel.umd.js',
4+
sourceMap: false,
5+
format: 'umd',
6+
moduleName: 'ng.ngucarousel',
7+
external: [
8+
'@angular/core',
9+
'@angular/common',
10+
'@angular/platform-browser',
11+
'rxjs/Subject'
12+
],
13+
globals: {
14+
'@angular/core': 'ng.core',
15+
'@angular/common': 'ng.common',
16+
'@angular/platform-browser': 'ng.platform-browser',
17+
'rxjs/Observable': 'Rx',
18+
'rxjs/Subject': 'Rx',
19+
'rxjs/ReplaySubject': 'Rx',
20+
'rxjs/add/operator/map': 'Rx.Observable.prototype',
21+
'rxjs/add/operator/mergeMap': 'Rx.Observable.prototype',
22+
'rxjs/add/observable/fromEvent': 'Rx.Observable',
23+
'rxjs/add/observable/of': 'Rx.Observable'
24+
}
25+
};

0 commit comments

Comments
 (0)