Skip to content

Commit f0cf77e

Browse files
authored
Merge pull request mendhak#110 from millerscout/ngintroAsService
Introduced ngIntroService.
2 parents 2361357 + 47845b2 commit f0cf77e

File tree

6 files changed

+403
-201
lines changed

6 files changed

+403
-201
lines changed

README.md

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,21 @@ This project will return the whole angular module so if you want to use as a dep
2929

3030
## How to use
3131

32-
The two main directives are `ng-intro-options` and `ng-intro-method`.
32+
You can use the two main directives, which are `ng-intro-options` and `ng-intro-method`, or you can include the service called `ngIntroService`
3333

3434
### Setting Options
3535

36-
`ng-intro-options="IntroOptions"`
36+
**As a directive** - `ng-intro-options="IntroOptions"`
37+
38+
**As a service** - `ngIntroService.setOptions(IntroOptions)`
3739

3840
You should create a `$scope.IntroOptions` in your controller which contains the intro.js options. The options are exactly the same as [the original](https://github.com/usablica/intro.js/wiki/Documentation#options). This also allows you to modify the options as part of your controller behavior if necessary. You don't have to use `IntroOptions`, you can specify some other name.
3941

4042
### Start method
4143

42-
`ng-intro-method="CallMe"`
44+
**As a directive** - `ng-intro-method="CallMe"`
45+
46+
**As a service** - `ngIntroService.start()`
4347

4448
The directive will create a method on `$scope.CallMe` so that you can invoke it yourself later. Make sure the there isn't a method `CallMe` already in your controller. To use the method be sure to wrap it with `$timeout`. You don't have to use `CallMe`, you can specify some other name.
4549

@@ -61,10 +65,12 @@ If you set `ng-intro-autostart="true"`, the intro will start as soon as the dire
6165

6266
If an intro tour includes dynamic content, use `ng-intro-autorefresh="true"` to call Intro.js' refresh method.
6367

64-
### Callbacks
68+
## Callbacks
6569

6670
Intro.js provides several callbacks. You can receive these callbacks in your controller. For example, for the `onchange` event, specify the function name in the directive.
6771

72+
### As a directive
73+
6874
`ng-intro-onchange="ChangeEvent"`
6975

7076
In your controller, create `ChangeEvent`
@@ -77,17 +83,61 @@ In your controller, create `ChangeEvent`
7783

7884
The other intro.js callbacks you can specify are `ng-intro-oncomplete`, `ng-intro-onexit`, `ng-intro-onchange` `ng-intro-onbeforechange` and `ng-intro-onafterchange`.
7985

86+
### As a service
87+
88+
There are two ways of make use of callbacks:
89+
90+
**Using promises**
91+
92+
The methods that return promises:
93+
94+
* `onComplete`
95+
* `onExit`
96+
* `onBeforeChange`
97+
* `onAfterChange`
98+
* `onChange`
99+
100+
**Using watches (not recommended, available for compatibility)**
101+
102+
`scope.$on('ngIntro-onAfterChange', function () {
103+
ngIntro.exit();
104+
´
105+
Its triggers are:
106+
107+
* `ngIntro-onComplete`
108+
* `ngIntro-onBeforeChange`
109+
* `ngIntro-onChange`
110+
* `ngIntro-onAfterChange`
111+
* `ngIntro-onExit`
112+
113+
* `ngIntro-onHintclick`
114+
* `ngIntro-onHintclose`
115+
* `ngIntro-onHintsAdded`
116+
117+
118+
119+
80120
### Exit Method
81121

82-
`ng-intro-exit-method="ExitMe"`
122+
**Directive** - `ng-intro-exit-method="ExitMe"`
123+
**Callback** - `$scope.ExitMe(function() { //callback } );`
83124

84-
Then in your controller, you can force exit using
125+
You can also call `$scope.ExitMe()` from your controller.
126+
127+
128+
**Service** - `ngIntroService.exit()`
129+
**Callback** - `ngIntroService.onExit().then(function(){
130+
console.log('do something.')
131+
});`
85132

86-
`$scope.ExitMe(function() { //callback } );`
87133

88134
### Plunker
89135

90-
You can also use this [sample plunker](http://plnkr.co/edit/wo9EzfbOFjM7NDoAvmjA?p=preview)
136+
You may use as Directive [as shown here](http://plnkr.co/edit/wo9EzfbOFjM7NDoAvmjA?p=preview)
137+
138+
or
139+
140+
alternatively as Service [as shown here](http://plnkr.co/edit/4JdONL)
91141

92142
## How to build
93143

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-intro.js",
3-
"version": "3.0.1",
3+
"version": "3.2.0",
44
"main": "src/angular-intro.js",
55
"description": "Angular directive to wrap intro.js",
66
"license": "MIT",

build/angular-intro.min.js

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

0 commit comments

Comments
 (0)