Angular Pathパラメーターを組み合わせる?

Oct 07 2020

Angular Material Docsアプリケーションは、次のようなパスパラメータを組み合わせます。

    // Combine params from all of the path into a single object.
    this.params = combineLatest(
        this._route.pathFromRoot.map(route => route.params), Object.assign);

次に例を示します。 https://github.com/angular/material.angular.io/blob/master/src/app/pages/component-category-list/component-category-list.ts

ただし、これによりエラーが発生します。

@deprecated — resultSelectorはサポートされなくなり、代わりにマップにパイプします

したがって、それを回避するためにこれを行うことが可能です:

    this.params = combineLatest(
      this._route.pathFromRoot.map(route => route.params)
    ).pipe(
        map(Object.assign)
    );

ここに記載されているように:@deprecatedのcombineLatestリファクタリング— resultSelectorはサポートされなくなり、代わりにマップにパイプしますか?

ただし、このエラーが発生します。

エラーTypeError:SafeSubscriber .__ tryOrUnsub(Subscriber.js:183)at SafeSubscriber.next(Subscriber.js:122)atSubscriberのSafeSubscriber._next(component-category-list.ts:50)で未定義のプロパティ 'name'を読み取ることができません._next(Subscriber.js:72)at Subscriber.next(Subscriber.js:49)at MapSubscriber._next(map.js:35)at MapSubscriber.next(Subscriber.js:49)at CombineLatestSubscriber.notifyNext(combineLatest.js :73)InnerSubscriber._next(InnerSubscriber.js:11)at InnerSubscriber.next(Subscriber.js:49)at BehaviorSubject._subscribe(BehaviorSubject.js:14)at BehaviorSubject._trySubscribe(Observable.js:42)atBehaviorSubject。 _trySubscribe(Subject.js:81)at BehaviorSubject.subscribe(Observable.js:28)at subscribeToResult(subscribeToResult.js:9)

そのためsection、コンポーネントが探しているURLパラメーターは、リファクタリング後にキャプチャされなくなったように見えます。考え?

回答

Ole Oct 09 2020 at 11:23

次のObject.assignように渡す場合は、パラメータを分解する必要があります。


    // Combine params from all of the path into a single object.
    this.params = combineLatest(
      this._route.pathFromRoot.map(route => route.params)).
      pipe(map((params:Params[])=>Object.assign({}, ...params)));