Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 指向被视为路由相对路径的外部URL的2个链接_Javascript_Angular_Components_Property Binding - Fatal编程技术网

Javascript 指向被视为路由相对路径的外部URL的2个链接

Javascript 指向被视为路由相对路径的外部URL的2个链接,javascript,angular,components,property-binding,Javascript,Angular,Components,Property Binding,我创建了一个组件,该组件接收在其选择器上设置的属性: <app-navigation-card label="My Label" description="Description of Item" type="download" [links]="[{path:'https://somedomain.com/somefile.zip', label:'Download'}]" ></app-navigation-c

我创建了一个组件,该组件接收在其选择器上设置的属性:

<app-navigation-card
        label="My Label"
        description="Description of Item"
        type="download"
        [links]="[{path:'https://somedomain.com/somefile.zip', label:'Download'}]"
></app-navigation-card>
在模板中:

<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>
{{label}
{{description}}



你应该考虑创建一个锚标签,因为它看起来是一个外部URL,它将下载一个文件。而是删除

*ngIf
,只使用
*ngFor
的第一个元素,而不使用
span
包装器

另外,删除添加到li元素的routerLink,由于事件冒泡,该元素将触发router.navigate函数

<li *ngFor="let link of links">
    <a [attr.href]="link.path">{{link.label}}</a>
</li>



或者从控制器中使用
单击
事件和调用功能,并使用
窗口在新选项卡中打开路径。打开(路径)
。它将自动下载文件。

据我所知,这绕过了内部路由(SPA)的全部目的,本质上是该URL网站的一个新热点。@ChrisWhite这是路由器不应该知道此外部URL导航的特定情况,因为我们使用了
href
。。
<li *ngFor="let link of links">
    <a [attr.href]="link.path">{{link.label}}</a>
</li>