Created
October 24, 2020 21:54
-
-
Save dixavier27/6e7eb89f4a61db8b40b82cfdeaeade6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { | |
Resolve, | |
ActivatedRouteSnapshot, | |
RouterStateSnapshot, | |
} from '@angular/router'; | |
import { Observable } from 'rxjs'; | |
import { CoffeeOrder, OrdersService } from './shared/orders.service'; | |
@Injectable({ | |
providedIn: 'root', | |
}) | |
export class GetCoffeeOrdersResolverService implements Resolve<CoffeeOrder[]> { | |
constructor(private ordersService: OrdersService) {} | |
resolve( | |
route: ActivatedRouteSnapshot, | |
state: RouterStateSnapshot | |
): Observable<CoffeeOrder[]> | any { | |
console.log('GetCoffeeOrdersResolver'); | |
// this.ordersService.getCoffeeOrders().subscribe((res) => { | |
// console.log(res); | |
// }); | |
return this.ordersService.getCoffeeOrders(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
import { ActivatedRoute } from '@angular/router'; | |
@Component({ | |
selector: 'app-order-list', | |
templateUrl: './order-list.component.html', | |
styleUrls: ['./order-list.component.css'], | |
}) | |
export class OrderListComponent implements OnInit { | |
coffeeOrders; | |
res; | |
constructor(private route: ActivatedRoute) {} | |
ngOnInit() { | |
console.log('ngOnInit'); | |
this.route.data.subscribe(res => { | |
console.log(res); | |
this.res = res; | |
}) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { HttpClient } from '@angular/common/http'; | |
import { Injectable } from '@angular/core'; | |
import { AngularFirestore } from '@angular/fire/firestore'; | |
export class CoffeeOrder { | |
coffeeOrder: string[]; | |
completed: boolean; | |
customerName: string; | |
orderNumber: number; | |
} | |
@Injectable({ | |
providedIn: 'root', | |
}) | |
export class OrdersService { | |
constructor(private firestore: AngularFirestore, private http: HttpClient) {} | |
// getCoffeeOrders() { | |
// return this.firestore.collection('coffeeOrders').snapshotChanges(); | |
// } | |
getCoffeeOrders() { | |
console.log('OrdersService') | |
let request = this.http.get('http://date.jsontest.com/'); | |
// request.toPromise().then(res => console.log(res)) | |
return request; | |
// let orders = this.firestore | |
// .collection<CoffeeOrder>('coffeeOrders') | |
// .valueChanges(); | |
// // console.log(orders); | |
// return orders; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment