我创建了一个组件,它接收在它的选择器上设置的属性:
<app-navigation-card
label="My Label"
description="Description of Item"
type="download"
[links]="[{path:'https://somedomain.com/somefile.zip', label:'Download'}]"
></app-navigation-card>
输入在 NavigationCard 类中设置:
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'app-navigation-card',
templateUrl: './navigation-card.component.html',
styleUrls: ['./navigation-card.component.scss']
})
export class NavigationCardComponent implements OnInit {
@Input() label: String;
@Input() description: String;
@Input() links: Object;
@Input() type: String;
constructor() { }
ngOnInit() {
}
}
在模板中:
<div class="label">{{label}}</div>
<div class="description">{{description}}</div>
<ul *ngIf="links != undefined" class="links">
<li *ngFor="let link of links" [routerLink]="link.path">
<span *ngIf="type == 'download'"><a href="{{link.path}}">{{link.label}}</a></span>
<span *ngIf="type == 'navigation'" [routerLink]="link.path"><{{link.label}}</span>
<div></div>
</li>
</ul>
如果 type == navigation
,路由器将重定向到正确的组件,但是当它是下载时,我收到此错误:
例外:未捕获(承诺):错误:无法匹配任何路由。URL 段:'style-guide/https%3A/somedomain.com/somefile.zip'
当在链接的 href 中显式输入但不是通过属性绑定时,此 URL 可以正常工作。知道如何解决这个问题吗?