2017-12-26 5 views

답변

0

다른 사람이 답을해야하는 경우 :

this.route.paramMap.subscribe(data => { 
    console.log('this routes to =>', data, name); 
    }); 
이 경로 매개 변수를 검색하면

this.route.paramMap.subscribe(params => { 
    this.name = params.get('id') 
}); 

는 쿼리 연산자를 사용하는 경우 FireStore에서 일치하는 문서를 요청

-1

당신이해야한다고 생각 :

import { ActivatedRoute } from '@angular/router'; 

export class CategoriesComponent { 

     ngOninit() { 
     this.route$ = this.activatedRoute.queryParams.subscribe((params: 
     Params) => { 
     if (params) { 
     console.log(params['collection']); 
     } else { 
     console.log(params['items']); 
     } 
     }); 

이 데이터베이스 구조입니다 :는 TS 내가 경로로 제품

이의 이름을 기준으로 제품 페이지에 카테고리 페이지가 필요하다 URL 매개 변수를 구독하십시오. ngOnInit

ngOnInit() { 
    this.sub = this.route.params.subscribe(params => { 
    console.log(params['collection']); 
    console.log(params['items']);. 
    }); 
} 
+1

두 가지 모두에 대해 '정의되지 않음'이 표시됩니다. – Famous

+0

URL은 어떤 모양입니까? –

+0

다음은 공개 repo => https://bitbucket.org/FamousTM/angular5com – Famous

0

y의 구조와 이름에 대한 정보가 많지 않습니다. 우리의 Firestore 데이터베이스;

constructor(
    public afAuth: AngularFireAuth, 
    db: AngularFirestore, 
    private route: ActivatedRoute, 
    private productsService: ProductsService, 
    private afs: AngularFirestore 
) { 
    this.afAuth.auth.signInAnonymously(); 
    this.user = this.afAuth.authState; 
    this.route.paramMap.subscribe(params => { 
    this.name = params.get('id') 
    }); 
} 

ngOnInit() { 
    this.itemCollection = this.afs.collection<Item>('items', ref => { 
    return ref.where('name', '==', this.name); 
    }); 
    this.items = this.itemCollection.valueChanges(); 
    this.items.subscribe(data => { 
    console.log(data) 
    }) 
} 

여기의 차이는 내가 먼저 생성자는 경로의 PARAMS에 가입하고 주소 표시 줄에서 이름을 검색 할 수 있다는 점이다 : 그러나,이 주사를. 당신이 당신의 라우터 모듈에 :id라는 이름의 매개 변수를 가지고 있기 때문에


솔루션

, 당신은이 같은 식별자 매개 변수 값을 검색해야합니다. 이것은 나를 위해 일한

this.itemCollection = this.afs.collection<Item>('items', ref => { 
    return ref.where('name', '==', this.name); 
}); 
+0

죄송합니다. 'name.'을'this.name' 대신에'ref.where()'메쏘드에 건네주었습니다. 이제 작동합니다. 이전 댓글을 삭제하십시오. – Trent