Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 2de44ab

Browse files
Best practice to init firebase #613
1 parent c03893f commit 2de44ab

File tree

4 files changed

+39
-34
lines changed

4 files changed

+39
-34
lines changed

demo-ng/app/app.component.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
import { Component } from "@angular/core";
1+
import { Component, OnInit } from "@angular/core";
2+
const firebase = require("nativescript-plugin-firebase/app");
23

34
@Component({
4-
selector: "ns-app",
5-
templateUrl: "app.component.html",
5+
selector: "ns-app",
6+
templateUrl: "app.component.html",
67
})
78

8-
export class AppComponent { }
9+
export class AppComponent implements OnInit {
10+
11+
ngOnInit(): void {
12+
firebase.initializeApp({
13+
persist: false
14+
}).then(() => {
15+
console.log("Firebase initialized");
16+
});
17+
}
18+
19+
}

demo-ng/app/item/items.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
<Label [text]="(myCity$ | async).name" height="32" *ngIf="myCity$"></Label>
2626
<Button text="Collection Observable (cities)" (tap)="firestoreCollectionObservable()" class="button"></Button>
2727
<ListView [items]="myCities$ | async" height="200" *ngIf="myCities$">
28-
<template let-item="item">
28+
<ng-template let-item="item">
2929
<StackLayout>
3030
<Label style="color: red" [text]='item.name'></Label>
3131
</StackLayout>
32-
</template>
32+
</ng-template>
3333
</ListView>
3434
<Button text="Listen to changes in SF" (tap)="firestoreListen()" class="button"></Button>
3535
<Button text="Stop listening" (tap)="firestoreStopListening()" class="button"></Button>

demo-ng/app/item/items.component.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, NgZone, OnInit } from "@angular/core";
1+
import { Component, NgZone } from "@angular/core";
22
import { firestore } from "nativescript-plugin-firebase";
33
import { Observable } from "rxjs/Observable";
44
import { City } from "../model/City";
@@ -13,7 +13,7 @@ const firebaseWebApi = require("nativescript-plugin-firebase/app");
1313
moduleId: module.id,
1414
templateUrl: "./items.component.html",
1515
})
16-
export class ItemsComponent implements OnInit {
16+
export class ItemsComponent {
1717

1818
private listenerUnsubscribe: () => void;
1919

@@ -26,14 +26,6 @@ export class ItemsComponent implements OnInit {
2626
// AngularFireModule.initializeApp({});
2727
}
2828

29-
ngOnInit(): void {
30-
firebase.initializeApp({
31-
persist: false
32-
}).then(() => {
33-
console.log("Firebase initialized");
34-
});
35-
}
36-
3729
public loginAnonymously(): void {
3830
firebase.auth().signInAnonymously()
3931
.then(() => console.log("Logged in"))

demo-ng/package.json

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,39 @@
66
"nativescript": {
77
"id": "org.nativescript.firebasedemo.firestore",
88
"tns-ios": {
9-
"version": "3.4.0"
9+
"version": "3.4.1"
1010
},
1111
"tns-android": {
12-
"version": "3.4.0"
12+
"version": "3.4.1"
1313
}
1414
},
1515
"dependencies": {
16-
"@angular/animations": "~4.4.1",
17-
"@angular/common": "~4.4.1",
18-
"@angular/compiler": "~4.4.1",
19-
"@angular/core": "~4.4.1",
20-
"@angular/forms": "~4.4.1",
21-
"@angular/http": "~4.4.1",
22-
"@angular/platform-browser": "~4.4.1",
23-
"@angular/router": "~4.4.1",
16+
"@angular/animations": "~5.2.0",
17+
"@angular/common": "~5.2.0",
18+
"@angular/compiler": "~5.2.0",
19+
"@angular/core": "~5.2.0",
20+
"@angular/forms": "~5.2.0",
21+
"@angular/http": "~5.2.0",
22+
"@angular/platform-browser": "~5.2.0",
23+
"@angular/platform-browser-dynamic": "~5.2.0",
24+
"@angular/router": "~5.2.0",
2425
"angularfire2": "^5.0.0-rc.4",
2526
"firebase": "^4.6.2",
26-
"nativescript-angular": "~4.4.0",
27+
"nativescript-angular": "~5.2.0",
2728
"nativescript-plugin-firebase": "5.1.3",
28-
"nativescript-theme-core": "~1.0.2",
29-
"reflect-metadata": "~0.1.8",
30-
"rxjs": "~5.4.2",
31-
"tns-core-modules": "~3.3.0",
32-
"zone.js": "~0.8.2"
29+
"nativescript-theme-core": "~1.0.4",
30+
"reflect-metadata": "~0.1.10",
31+
"rxjs": "~5.5.0",
32+
"tns-core-modules": "~3.4.0",
33+
"zone.js": "~0.8.18"
3334
},
3435
"devDependencies": {
36+
"@angular/compiler-cli": "~5.2.0",
3537
"babel-traverse": "6.26.0",
3638
"babel-types": "6.26.0",
3739
"babylon": "6.18.0",
3840
"lazy": "1.0.11",
39-
"nativescript-dev-typescript": "~0.5.0",
40-
"typescript": "~2.4.2"
41+
"nativescript-dev-typescript": "~0.6.0",
42+
"typescript": "~2.6.2"
4143
}
4244
}

0 commit comments

Comments
 (0)