Angular 2: How to conditionally load a Component in a Route asynchronously?

前端 未结 6 639
花落未央
花落未央 2021-01-31 10:39

I\'d like to attach a component to a route asynchronously, given a condition.

The following example, which works (but is asynchronous), loads one compon

6条回答
  •  梦毁少年i
    2021-01-31 11:17

    You could just define a higher-level component f.e. DashboardComponent which is included at route /dashboards

    The parent component is then supposed to load the children in its template based on the asynchronous condition.

    This way you will also need to use the *ngIf but at least its not cluttering the child components templates.

提交回复
热议问题