我正在使用
我想做的事
问题
问题
组件
我指的是:if(数据类型!=='未定义'&& data.length> 0){ this.noResults = false; }
import { Component, OnInit } from '@angular/core';
// Firestore
import { Observable } from 'rxjs/Observable';
import { AngularFirestore, AngularFirestoreCollection } from 'angularfire2/firestore';
// Routes
import { Router, ActivatedRoute } from '@angular/router';
// Moment JS
declare var moment: any;
@Component({
selector: 'app-albums-list',
templateUrl: './albums-list.component.html',
styleUrls: ['./albums-list.component.css']
})
export class albumsListComponent implements OnInit {
private albumCollection: AngularFirestoreCollection<any>;
albums: Observable<any[]>;
folderId: string;
noResults = true;
constructor(
private readonly afs: AngularFirestore,
private activatedRoute: ActivatedRoute,
private router: Router
) { }
/* ngOnInit */
ngOnInit() {
// Look at the url for the Folder ID and set the local variable
this.activatedRoute.params.forEach((urlParameters) => {
this.folderId = urlParameters['folderId'];
});
// Return the albums list
this.getalbumListData();
}
/* RETURN album LIST DATA */
getalbumListData() {
// album Reference "folders/folderid/albums"
this.albumCollection = this.afs.collection<any>(`folders/${this.folderId}/albums`, ref => {
return ref.orderBy('album_title');
});
// Get the data
this.albums = this.albumCollection.snapshotChanges().map(actions => {
return actions.map(a => {
const data = a.payload.doc.data();
// If there's no returned data, set the 'noResults' variable
if (typeof data !== 'undefined' && data.length > 0) {
this.noResults = false;
}
const id = a.payload.doc.id;
return { id, ...data };
});
});
}
}
&#13;