我有这个方法:
validateinformations() {
this.valid = this.r ? this.r.filter((required: string) => !this[required] || !Object.keys(this[required]).length) : [];
!this.valid.length || this.message.warning("Evidencija mora da sadrži (" + this.valid.join(", ").toUpperCase() + ") korisnika!");
}
在我的HTML中我有这个:
<a (click)="validateinformations()" *ngIf="!children?.eligibilityInfo?.disabled" class="choose_offer {{!children.processId || !children.processId[0] ? 'disabled' : ''}}" [routerLink]="valid.length==0 ? ['/evidencija/',type, children.key, query.SPECIFICATION_ID, 0] : []" routerLinkActive="active" [queryParams]="valid?.length==0 ? {processId:children.processId && children.processId[0] ? children.processId[0] : children.processId ? children.processId : null,} : {}" queryParamsHandling="merge" >ODABERI</a>
我有问题因为因为有效我总是长度为0所以条件为真并且它将我重定向到另一页。任何建议如何解决这个问题?因为它在validateinformation执行之前重定向我。
答案 0 :(得分:2)
最好的方法是重定向你的功能:
import { Router } from '@angular/router';
constructor(_router:Router){}
validateinformations() {
this.valid = this.r ? this.r.filter((required: string) => !this[required] || !Object.keys(this[required]).length) : [];
!this.valid.length || this.message.warning("Evidencija mora da sadrži (" + this.valid.join(", ").toUpperCase() + ") korisnika!");
if(this.valid.length==0)
this._router.navigate(['/evidencija/',type, children.key, query.SPECIFICATION_ID, 0]);
}