【问题标题】:While routing to a secondary outlet, can I use a string as the named outlet?在路由到辅助插座时,我可以使用字符串作为命名插座吗?
【发布时间】:2019-04-30 22:53:28
【问题描述】:

我正在构建一个系统,该系统将动态内容路由到使用辅助(命名)路由器插座。

示例:

HTML

<div id="col1'>
   <router-outlet name="col1"></router-outlet>
</div>
<div id="col2'>
   <router-outlet name="col2"></router-outlet>
</div>

TypeScript

for (let c of this.containers) {
   switch (c.containerKey) {
     case "col1":
        this._router.navigate([{ outlets: { col1: [c.id] } }]);
       break;
     case "col2":
         this._router.navigate([{ outlets: { col2: [c.id] } }]);
         break;
   }
}

是否可以移除开关盒并使用c.containerKey 作为命名插座?

示例

for (let c of this.containers) {
   this._router.navigate([{ outlets: { c.containerKey: [c.id] } }]);
}

我知道上面的例子工作。但是有没有办法实现类似的目标?

【问题讨论】:

    标签: angular angular7 angular-routing


    【解决方案1】:

    您应该能够通过在 c.containerKey 周围添加 [ ] 来使用计算的属性名称,如下所示:

    this._router.navigate([{ outlets: { [c.containerKey]: [c.id] } }]);
    

    【讨论】:

      猜你喜欢
      • 2017-02-15
      • 1970-01-01
      • 1970-01-01
      • 2020-01-13
      • 2017-02-21
      • 2018-12-24
      • 1970-01-01
      • 2021-03-13
      相关资源
      最近更新 更多