You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/1-install-and-setup.md
+5-26Lines changed: 5 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -1,35 +1,13 @@
1
1
# 1. Installation and Setup
2
2
3
-
> Getting started with AngularFire2 is easy with the [Angular CLI](https://github.com/angular/angular-cli). Follow the 10 steps below to get started. Don't worry, we're always working to make this shorter.
4
-
5
3
> Using Ionic and the Ionic CLI? Check out these [specific instructions](6-angularfire-and-ionic-cli.md) for Ionic and their CLI.
6
4
7
5
### 0. Prerequisites
8
6
9
-
Before you start installing AngularFire2, make sure you have latest version of angular-cli installed.
10
-
To verify run the command `ng -v` and ensure you see `angular-cli: 1.x.x-beta.xx`. The lowest compatible version is `1.x.x-beta.14`.
11
-
12
-
If not, you may need to do the following:
13
-
14
-
```bash
15
-
# if you have the wrong cli version only
16
-
npm uninstall -g angular-cli
17
-
npm uninstall -g @angular/cli
18
-
npm cache clean
19
-
20
-
# reinstall clean version
21
-
npm install -g @angular/cli@latest
22
-
```
23
-
24
-
You need the Angular CLI, typings, and TypeScript.
7
+
AngularFire provides multiple module formats for different types of builds. The guide is based off the Angular CLI. It is possible to do a manual setup with Webpack or a SystemJS build as well.
25
8
26
9
```bash
27
-
npm install -g @angular/cli@latest
28
-
# or install locally
29
-
npm install @angular/cli --save-dev
30
-
# make sure you have typings installed
31
-
npm install -g typings
32
-
npm install -g typescript
10
+
npm install @angular/cli
33
11
```
34
12
35
13
### 1. Create a new project
@@ -50,13 +28,13 @@ open http://localhost:4200
50
28
51
29
You should see a message that says *App works!*
52
30
53
-
### 3. Install AngularFire 2 and Firebase
31
+
### 3. Install AngularFire and Firebase
54
32
55
33
```bash
56
34
npm install angularfire2 firebase --save
57
35
```
58
36
59
-
Now that you have a new project setup, install AngularFire2 and Firebase from npm.
37
+
Now that you have a new project setup, install AngularFire and Firebase from npm.
60
38
61
39
### 4. Add Firebase config to environments variable
62
40
@@ -79,6 +57,7 @@ export const environment = {
79
57
### 5. Setup @NgModule for the AngularFireModule
80
58
81
59
Open `/src/app/app.module.ts`, inject the Firebase providers, and specify your Firebase configuration.
60
+
82
61
This can be found in your project at [the Firebase Console](https://console.firebase.google.com):
The table below highlights some of the common methods on the `FirebaseObjectObservable`.
72
+
The table below highlights some of the common methods on the `AngularFireObject`.
81
73
82
74
| method ||
83
75
| ---------|--------------------|
84
-
|`set(value: any)`| Replaces the current value in the database with the new value specified as the parameter. This is called a **destructive** update, because it deletes everything currently in place and saves the new value. |
85
-
|`update(value: Object)`| Updates the current value with in the database with the new value specified as the parameter. This is called a **non-destructive** update, because it only updates the values specified. Note: Only values at the key level are non-destructive. |
76
+
|`set(value: T)`| Replaces the current value in the database with the new value specified as the parameter. This is called a **destructive** update, because it deletes everything currently in place and saves the new value. |
77
+
|`update(value: T)`| Updates the current value with in the database with the new value specified as the parameter. This is called a **non-destructive** update, because it only updates the values specified. |
86
78
|`remove()`| Deletes all data present at that location. Same as calling `set(null)`. |
87
79
88
80
## Returning promises
89
81
Each data operation method in the table above returns a promise. However,
90
82
you should rarely need to use the completion promise to indicate success,
91
83
because the realtime database keeps the object in sync.
92
84
93
-
The promise can be useful to chain multiple operations, catching possible errors
94
-
from security rules denials, or for debugging.
85
+
The promise can be useful to chain multiple operations, catching possible errors from security rules denials, or for debugging.
95
86
96
87
```ts
97
-
const promise =db.object('/item').remove();
88
+
const promise =db.object('item').remove();
98
89
promise
99
90
.then(_=>console.log('success'))
100
91
.catch(err=>console.log(err, 'You dont have access!'));
@@ -105,17 +96,17 @@ promise
105
96
Use the `set()` method for **destructive updates**.
106
97
107
98
```ts
108
-
constitemObservable=db.object('/item');
109
-
itemObservable.set({ name: 'new name!'});
99
+
constitemRef=db.object('item');
100
+
itemRef.set({ name: 'new name!'});
110
101
```
111
102
112
103
### Updating data
113
104
114
105
Use the `update()` method for **non-destructive updates**.
115
106
116
107
```ts
117
-
constitemObservable=db.object('/item');
118
-
itemObservable.update({ age: newAge });
108
+
constitemRef=db.object('item');
109
+
itemRef.update({ age: newAge });
119
110
```
120
111
121
112
**Only objects are allowed for updates, not primitives**. This is because
@@ -125,15 +116,15 @@ using an update with a primitive is the exact same as doing a `.set()` with a pr
125
116
Use the `remove()` method to remove data at the object's location.
@@ -177,15 +170,16 @@ Data retrieved from the object binding contains special properties retrieved fro
177
170
AngularFire2 unwraps the Firebase DataSnapshot by default, but you can get the data as the original snapshot by specifying the `preserveSnapshot` option.
Because `FirebaseObjectObservable` synchronizes objects from the realtime database, sorting will have no effect for queries that are not also limited by a range. For example, when paginating you would provide a query with a sort and filter. Both the sort operation and the filter operation affect which subset of the data is returned by the query; however, because the resulting object is simply json, the sort order will not be preseved locally. Hence, for operations that require sorting, you are probably looking for a [list](3-retrieving-data-as-lists.md)
183
+
Because `AngularFireObject` synchronizes objects from the realtime database, sorting will have no effect for queries that are not also limited by a range. For example, when paginating you would provide a query with a sort and filter. Both the sort operation and the filter operation affect which subset of the data is returned by the query; however, because the resulting object is simply json, the sort order will not be preseved locally. Hence, for operations that require sorting, you are probably looking for a [list](3-retrieving-data-as-lists.md)
190
184
191
185
### [Next Step: Retrieving data as lists](3-retrieving-data-as-lists.md)
0 commit comments