angular / angularfire

Angular + Firebase = ❤️
https://firebaseopensource.com/projects/angular/angularfire2
MIT License
7.69k stars 2.19k forks source link

Ducumentation Issues #1180

Closed Anystrous closed 7 years ago

Anystrous commented 7 years ago

Since the update the documentation examples are completely broken.

For example: This list example wont compile

import { Component } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
import { Observable } from 'rxjs/Observable';

@Component({
  selector: 'app-root',
  template: `
  <ul>
    <li *ngFor="let item of items | async">
      <input type="text" #updatetext [value]="item.text" />
      <button (click)="updateItem(item.$key, updatetext.value)">Update</button>
      <button (click)="deleteItem(item.$key)">Delete</button>
    </li>
  </ul>
  <input type="text" #newitem />
  <button (click)="addItem(newitem.value)">Add</button>
  <button (click)="deleteEverything()">Delete All</button>
  `,
})
export class AppComponent {
  itemsRef: Observable<any[]>;
  constructor(db: AngularFireDatabase) {
    this.itemsRef = db.list('messages').valueChanges();
  }
  addItem(newName: string) {
    this.itemsRef.push({ text: newName });
  }
  updateItem(key: string, newText: string) {
    this.itemsRef.update(key, { text: newText });
  }
  deleteItem(key: string) {    
    this.itemsRef.remove(key); 
  }
  deleteEverything() {
    this.itemsRef.remove();
  }
}

I get the error saying Property 'push' , 'update', 'remove' does not exist on type Observable<any[]>.

Yes I did update to version 5 using @next.

Previous examples were working great with version 4.

The dependencies are also incorrect in the Object example.

Please correct me if I am wrong.

davideast commented 7 years ago

@Anystrous

Update: I see the problem. The docs need this fix:

import { Component } from '@angular/core';
import { AngularFireDatabase, AngularFireList } from 'angularfire2/database';
import { Observable } from 'rxjs/Observable';

@Component({
  selector: 'app-root',
  template: `
  <ul>
    <li *ngFor="let item of items | async">
      <input type="text" #updatetext [value]="item.text" />
      <button (click)="updateItem(item.$key, updatetext.value)">Update</button>
      <button (click)="deleteItem(item.$key)">Delete</button>
    </li>
  </ul>
  <input type="text" #newitem />
  <button (click)="addItem(newitem.value)">Add</button>
  <button (click)="deleteEverything()">Delete All</button>
  `,
})
export class AppComponent {
  itemsRef: AngularFireList<any>;
  items: Observable<any[]>;
  constructor(db: AngularFireDatabase) {
    this.itemsRef = db.list('messages');
    this.items = this.itemsRef.valueChanges();
  }
  addItem(newName: string) {
    this.itemsRef.push({ text: newName });
  }
  updateItem(key: string, newText: string) {
    this.itemsRef.update(key, { text: newText });
  }
  deleteItem(key: string) {    
    this.itemsRef.remove(key); 
  }
  deleteEverything() {
    this.itemsRef.remove();
  }
}

We had breaking changes in version 5.0. There is a migration guide and if you want you can continue to use the old database API with angularfire2/database-deprecated.

The main difference in this sample is that FirebaseListObservable no longer exists and we switched to a Service Based API in AngularFireList<T>. This allows you to do data operations like push(), andset(). It also allows you to create different types of observable streams. You can get similar results with the old API in .valueChanges() and do tons of other great things with .snapshotChanges(), .stateChanges(), and .auditTrail().

I highly recommend using this API. Check out the documentation. File an issue if you find anything confusing. We're here to help :)

Anystrous commented 7 years ago

The problem is with new documentation. Please check it yourself

davideast commented 7 years ago

@Anystrous I updated my comment with a fix. We're working on the change right now.

Anystrous commented 7 years ago

Thank you.

gerhardcit commented 7 years ago

This is still wrong You are using <button (click)="updateItem(item.$key, updatetext.value)">Update</button> whilst the .valueChanges() does not provide a $key anymore.

Anthony2539 commented 7 years ago

Yes i don't understand how this can work with .valueChanges

How to use the$key simply in the template?

ayoubboumzebra commented 7 years ago

Hi, when i remove an item, all the data deleted in the same time, although i used the same code of @davideast, any idea ?

davideast commented 7 years ago

@ayoubboum Can you open a new issue that follows the template and gives a stackblitz?

davideast commented 7 years ago

Opening since the documentation still needs work.

ayoubboumzebra commented 7 years ago

I am new in github, i didn't get what you mean, sorry

davideast commented 7 years ago

@ayoubboum

On the main issue page (https://github.com/angular/angularfire2/issues/) create a new issue.

That issue will be populated with a template. That template asks you to tell the versions of Angular, Firebase, and AngularFire. Then when asking how to reproduce you can create a link to Stackblitz. Which is a super easy to use VSCode online editor. Create a little app that shows the problem and link it there. We'll then take a look at what's going on 👍

davideast commented 7 years ago

Fixed. Please open a new issue if you find any new problems.

ayoubboumzebra commented 7 years ago

Did you fixe my problem?

andy-parinas commented 7 years ago

Found a Fix on this problem:

this.db.object('listings').snapshotChanges().map(action =>{ const data = action.payload.toJSON(); return data; }).subscribe(result =>{ Object.keys(result).map(key=>{ this.listings.push({ 'key': key, 'data':result[key] }); }); console.log(this.listings) });

The snapshotChanges() returns an Object which needs to be converted to Array in order to be used in *ngFor

just create an array, in my example code: listings: any[] = []

then push the object with key and data as keys.

which then can be access in the template:

*ngFor="let listing of listings {{ listing.key}} {{listing.data}}

ayoubboumzebra commented 7 years ago

Thank you, i fixed it.

On Oct 13, 2017 12:55, "andy-parinas" notifications@github.com wrote:

Found a Fix on this problem:

this.db.object('listings').snapshotChanges().map(action =>{ const data = action.payload.toJSON(); return data; }).subscribe(result =>{ Object.keys(result).map(key=>{ this.listings.push({ 'key': key, 'data':result[key] }); }); console.log(this.listings) });

The snapshotChanges() returns an Object which needs to be converted to Array in order to be used in *ngFor

just create an array, in my example code: listings: any[] = []

then push the object with key and data as keys.

which then can be access in the template:

*ngFor="let listing of listings {{ listing.key}} {{listing.data}}

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/angular/angularfire2/issues/1180#issuecomment-336431309, or mute the thread https://github.com/notifications/unsubscribe-auth/APHL82eU0YKqFmwdNgiqsTtJmFWq5vE3ks5sr0-tgaJpZM4PsZjY .

abhinpai commented 6 years ago

Hello, when i tried to delete the specific node using $key entire data is going to delete any solution?

ayoubboumzebra commented 6 years ago

Hi, I didn't understand your question, basically when you try to delete any specific row, that row you've selected will be deleted.

http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail Garanti sans virus. www.avg.com http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Mon, Jan 29, 2018 at 6:49 AM, Abhin Pai notifications@github.com wrote:

Hello, when i tried to delete the specific node using $key entire data is going to delete any solution?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/angular/angularfire2/issues/1180#issuecomment-361154595, or mute the thread https://github.com/notifications/unsubscribe-auth/APHL8x-C_8Jn1V_Qp5-3Tz296rJrQ1R3ks5tPWnzgaJpZM4PsZjY .

abhinpai commented 6 years ago

Hi, When I remove a particular item at the same time all the item gets deleted from the database. I followed the same documentation of @davideast and I think my issue is pretty similar which you asked before @ayoubboum

ayoubboumzebra commented 6 years ago

Hi, that pretty weird because if you the video it's worked for me very well , sorry for that, but i'll check it again. Thanks

http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail Garanti sans virus. www.avg.com http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Tue, Jan 30, 2018 at 4:58 AM, Abhin Pai notifications@github.com wrote:

Hi, When I remove a particular item at the same time all the item gets deleted from the database. I followed the same documentation of @davideast https://github.com/davideast and I think my issue is pretty similar which you asked before @ayoubboum https://github.com/ayoubboum

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/angular/angularfire2/issues/1180#issuecomment-361477546, or mute the thread https://github.com/notifications/unsubscribe-auth/APHL8-IBK-WOLYgUZocV-VLV7pr6zrsYks5tPqGLgaJpZM4PsZjY .

ayoubboumzebra commented 6 years ago

Hi, I've just checked my source code and it's worked just fine.

On Tue, Jan 30, 2018 at 11:48 AM, ayoub boumzebra boumzebraa@gmail.com wrote:

Hi, that pretty weird because if you the video it's worked for me very well , sorry for that, but i'll check it again. Thanks

http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail Garanti sans virus. www.avg.com http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail <#m_-2196113848313040215_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Tue, Jan 30, 2018 at 4:58 AM, Abhin Pai notifications@github.com wrote:

Hi, When I remove a particular item at the same time all the item gets deleted from the database. I followed the same documentation of @davideast https://github.com/davideast and I think my issue is pretty similar which you asked before @ayoubboum https://github.com/ayoubboum

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/angular/angularfire2/issues/1180#issuecomment-361477546, or mute the thread https://github.com/notifications/unsubscribe-auth/APHL8-IBK-WOLYgUZocV-VLV7pr6zrsYks5tPqGLgaJpZM4PsZjY .

Heenash04 commented 6 years ago

Property do does not exist on firebaseAngularList.Can anyone please help me?

abhinpai commented 6 years ago

Use AngularFireList instead of firebaseAngularList, firebaseAngularList is replaced to AngularFireList in latest version of ionic

horlah commented 6 years ago

please am still unable to use $key in my html to get the key to a set of data, any way out?

ericmulcahy commented 6 years ago

I just want to share my experience, as someone trying to learn Firebase and Ionic. I started with a tutorial on Youtube "How to Build An Ionic App with Firebase and AngularFire 4" where you make a shopping list. Super, super basic. Then I figured, "why not upgrade to angularfire version 5?". I found this thread, and tried @davideast 's approach of using separate variables for "items" and "itemsRef". It seemed weird, why do I now need 2 views of basically the same thing? But it worked. Then I tried to remove an item, which means I needed to stop using item.$key. So I tried @andy-parinas 's approach of using snapshotChanges(), mapping it to an array, and all of that. Now I have 3 views of the same data, and it doesn't work at all - it displays on the screen, but items are repeated, and it fails when there are no items at all in the list. I have no idea why, and frankly, I don't care.

It's ridiculous. How is this better than the angularfire version 4 way? Why not provide a full working example?

Sorry to gripe, but I challenge anyone to link me to a basic working example that can display, add, and remove items from a list. How are beginners supposed to learn this?

ix-xerri commented 6 years ago

How do I catch permission denied errors on .push() with firebase validation on AF5?

markterrill commented 6 years ago

I'm interested to know as well how/where you catch errors

Bruswei commented 6 years ago

Anyone has an update on this? I am struggling to get AngularFire2 v 5.0.0 rc-9 up and running. :/

just67 commented 6 years ago

"How are beginners supposed to learn this?" same goes for me. it's very confusing with all those changes in the last 6 months and no useful up-to-date example.