ngx-hellojs
v0.1.2
Published
Use hellojs with Angular5~ (https://adodson.com/hello.js/)
Downloads
152
Readme
Ngx Hellojs
This module is used for Angular 5.
This module help you to use hellojs library as service.
How to use:
Installation:
npm install ngx-hellojs
Import library:
Edit .angular-cli.json
{
//...
"apps": [
{
//...
"scripts": [
//...
"../node_modules/hellojs/dist/hello.all.js"
],
//...
}
],
//...
}
Import service:
Edit in src/app/app.module.ts
:
//...
import { NgxHellojsModule, NgxHellojsService } from 'ngx-hellojs';
const helloJSCredentials = {
facebook: environment.credentials.facebook,
google: environment.credentials.google,
windows: environment.credentials.windows,
twitter: environment.credentials.twitter,
};
const helloJsOptions = {
scope: ['friends', 'email']
};
@NgModule({
//...
imports: [
//...
NgxHellojsModule.forRoot({
facebook: <facebook-app-id>,
google: <google-app-id>,
windows: <windows-app-id>,
twitter: <twitter-app-id>,
}, {
scope: 'friends, photos, publish'
}),
],
bootstrap: [AppComponent]
})
export class AppModule {
constructor(ngxHellojsService: NgxHellojsService) {
ngxHellojsService.init(helloJSCredentials, helloJsOptions);
}
}
//same with:
//hello.init({facebook: '<your-app-id>'}, {scope: 'friends, email'});
And call in component:
constructor(private _ngxHellojsService: NgxHellojsService) {
}
Login
<!-- Using directive -->
<p ngxLoginHellojs="facebook"
(successEvent)="loginSuccessfullyAction($event)"
(errorEvent)="loginFailedAction($event)">Login facebook</p>
this._ngxHellojsService
.login('facebook', {scope: 'friends, photos, publish'})
.subscribe(data => {}, error => {});
//same with:
//hello('facebook').login({scope: 'friends, photos, publish'})
// .then(function(data) {}, function(error) {});
Logout
<!-- Using directive -->
<p ngxLogoutHellojs="facebook"
(successEvent)="logoutSuccessfullyAction($event)"
(errorEvent)="logoutFailedAction($event)">Logout</p>
this._ngxHellojsService.logout('facebook')
.subscribe(data => {}, error => {});
//same with:
//hello('facebook').logout()
// .then(function(data) {}, function(error) {});
Get auth response
const fbResult = this._ngxHellojsService.getAuthResponse('facebook');
//same with:
//var fbResult = hello('facebook').getAuthResponse();
Call api
this._ngxHellojsService.api('facebook', 'me')
.subscribe(data => {}, error => {});
//same with:
//hello('facebook').api('me')
// .then(function(data) {}, function(error) {});
this._ngxHellojsService.api('facebook', 'me/friends', null, {limit: 1})
.subscribe(data => {}, error => {});
//same with:
//hello('facebook').api('me/friends', {limit: 1})
// .then(function(data) {}, function(error) {});
On / Off
messageAfterLogin = () => {
console.log('Login successfully');
}
this._ngxHellojsService.on('auth.login', this.messageAfterLogin);
this._ngxHellojsService.off('auth.login', this.messageAfterLogin);
//same with:
//var messageAfterLogin = function () {
// console.log('Login successfully');
//};
//
//hello.on('auth.login', messageAfterLogin);
//hello.off('auth.login', messageAfterLogin);