[英]Angular 4 button with click(returnsbooleanVAR) function and routerlink + boolean VAR timing
我有一個在(單擊)上具有功能的按鈕,該按鈕將變量“ routingActivated”設置為true或false,然后在同一按鈕中,如果該var為true,則鏈接到另一個組件的routerlink。一切正常,但為了運行到下一個組件,我必須單擊兩次按鈕。有關如何重新執行操作的任何想法,因此我只需要單擊一次即可?
這是按鈕:
<button (click)="check()" [routerLink]="routingActivated ? ['/enviando']: []" >Continue</button>
這是將var routingActivated更改為true或false的檢查功能
check():void{
routingActivated =true/false //depending on a condition
}
您可以直接在組件中重定向
import {Router} from '@angular/router';
export class InfoComponent {
constructor(private router: Router)
check():void{
if(routingActivated) {
this.router.navigate(['./enviando']);
}
}
}
並簡化您的HTML
<button (click)="check()">Continue</button>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.