-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configuring Ionic2/AngularFire2 and Auth #691
Comments
Isn't |
Nice! ☃ |
One comment on my end: In home.ts rather than using AngularFire in order to fetch list of "items" I would recommend to refer directly to AngularFireDatabase: ...
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2';
...
export class HomePage {
items: FirebaseListObservable<any[]>;
constructor(public navCtrl: NavController, private _db: AngularFireDatabase, private _auth: AuthService) {
this.items = _db.list('/items');
}
...
} Anyway thanks for sharing, looks pretty same as mine implementation 😄 |
Posting this here as well since I couldn't get the above to work without this modification. I had to add a custom rollup.config.js script (not sure every option here is actually needed):
from here https://forum.ionicframework.com/t/ionic-2-rc-0-and-firebase-not-angularfire/65018/7 Also have Note that you set where your custom config is in package.json with:
Hope this helps someone save some time |
@mukesh51 I did exactly what you wrote I get this error while run in android emulator
|
@adirzoari I didn't receive this error, but try adding this line to import * as firebase from 'firebase'; Also refer to issues #654 . Hope that helps. Also this issue is closed and you can refer to the tutorial here |
Version info
Angular:
2.1.1
Firebase:
^3.6.1
AngularFire:
^2.0.0-beta.6
Other (e.g. Ionic/Cordova, Node, browser, operating system):
ionic 2.1.12, corodova 6..4.0
How to reproduce these conditions
This is a document to help individuals who are having issues in configuring AngularFire2 in general and AngularFire2 Auth.
Failing test unit, Plunkr, or JSFiddle demonstrating the problem
N/A
Steps to set up and reproduce
N/A
Sample data and security rules
N/A
<-- include/attach/link to some json sample data (or provide credentials to a sanitized, test Firebase project) -->
Debug output
** Errors in the JavaScript console ** N/A
** Output from
firebase.database().enableLogging(true);
** N/A** Screenshots ** N/A
Expected behavior N/A. This is more of a tutorial
Actual behavior N/A
There have been few issues reported around integration of angularFire2 with Ionic2.
So thought of sharing this, so that it helps people getting started. The below setup have been executed on Windows 10, but it should be same for Mac and Linux.
Ensure that you're executing these commands as "Administrator" on Windows and "sudo" on Mac and Linux to avoid any errors.
Prerequisites
The first step is to ensure you've latest version of node installed. If not, you can get it installed from here. This will install both node and npm.
After installing node, check the version of node by executing the following command in your command prompt.
As of now, this is the most stable version. If you're not on this version, please upgrade yourself to latest version by installing node from here.
Check your npm version by executing the following command.
Your Application code sits on top of Ionic Framework and the Ionic Framework sits on top of Cordova. Let's get them installed globally, so that all projects can use them.
Execute the following commands.
C:\projects>npm install -g cordova
C:\projects>npm install -g ionic
Once the above commands are successful, check the versions of corodva and ionic by executing the following commands.
Once the above commands are executed, you're all set to create your Ionic 2 app.
To create your app, change into the directory where you want your app to reside and execute the following command
C:\projects> ionic start Ionic_AngularFire2_Project blank --v2
Change to the project directory, which was just created with above command
To ensure your app is running, execute the following command
C:\projects\Ionic_AngularFire2_Project> ionic serve
If everything is installed correctly, the app should open your browser with the dev server running at following url (http://localhost:8100) and display the default home page.
Stop you server by pressing "ctrl + c", if it is still running from the above step and install typings and typescript globally by executing the following commands:
Check typings and typescript versions by executing following commands:
Configuring AngularFire2 and Firebase
Install angularfire2 and firebase by executing the following command in your project directory
C:\projects\Ionic_AngularFire2_Project>npm install angularfire2 firebase --save
This should add angularfire2 and firebase entry in your project's package.json file in dependencies section. Something similar
Setup @NgModule
Open your project in your favourite editor and open the
app.module.ts
file, under src/appand add the following three entries.
your
app.module.ts
file should look something like this.Inject AngularFire and Bind it to List
Now inject AngularFire in your component. Open your
home.ts
by going intosrc/pages/home/home.ts
and make the following changes:Your
home.ts
file should look like this.Update your
home.html
atsrc/pages/home/home.html
, with following entryRun your app by executing the following command
C:\projects\Ionic_AngularFire2_Project> ionic serve
This should fetch you the data from firebase.
Configuring AngularFire2 Auth with Ionic2
Continuing with the above example stop your server by pressing
ctrl+c
and go to command prompt and generate a service by executing the following commandC:\projects\Ionic_AngularFire2_Project> ionic g provider AuthService
This should create the AuthService under
src/providers/auth-service.ts
.Update the service with the following code.
Add your service in
app.module.ts
. Yourapp.module.ts
should look like thisUpdate your
home.html
to add a login button. Yourhome.html
should look like thisand finally, add the corresponding click handlers in
home.ts
as follows. Also, ensure the AuthService is injected in the constructor. yourhome.ts
should look like thisNow run your app and if everything is configured correctly, you should be able to click on the login button in your app, which should open the facebook pop-up and once you're authenticated, you should see your Facebook display name in console. You can try redirecting yourself to another page to grab additional details.
Hope this helps.
Any Thoughts ?
The text was updated successfully, but these errors were encountered: