Angular 是否可以检测查询参数是否已更改?我有一个处理 2 个查询参数的组件,并根据你附带的参数设置一些变量 true 或 false。问题是如果我在我的组件上使用 queryparameter 1 qp 可以更改为第二个参数而不离开组件,在这种情况下我需要设置不同的变量。那么我该如何检测呢?这甚至可能吗?
我有一些输入(复选框),如果我的布尔值为true,我希望禁用它们。但是它不起作用...有趣的是,提交按钮可以正常工作,这就是相同的方法...
myComponent.html
<form [formGroup]="BetreuungsoptionForm" (ngSubmit)="onSubmit()">
<label *ngIf="!eingetragen" for="art">Art</label>
<select *ngIf="!eingetragen" formControlName="art" id="art" class="form-control" [(ngModel)]="Art" required >
<option value="festeAnmeldung">feste Anmeldung</option>
<option value="flexibleAnmeldung">flexible Anmeldung</option>
</select>
<label for="datum">Beginn Datum</label>
<input formControlName="datum" type="date" id="datum" class="form-control" required>
<label *ngIf="(Art == 'festeAnmeldung')" for="montag">Montag</label>
<input *ngIf="(Art == 'festeAnmeldung')" formControlName="montag" [disabled]="montag" type="checkbox" id="montag" class="form-control wochentag">
<label *ngIf="(Art == 'festeAnmeldung')" for="dienstag">Dienstag</label>
<input *ngIf="(Art == 'festeAnmeldung')" formControlName="dienstag" [disabled]="dienstag" type="checkbox" id="dienstag" class="form-control wochentag">
<label *ngIf="(Art == 'festeAnmeldung')" for="mittwoch">Mittwoch</label>
<input *ngIf="(Art == 'festeAnmeldung')" formControlName="mittwoch" [disabled]="mittwoch" type="checkbox" id="mittwoch" class="form-control wochentag">
<label *ngIf="(Art == …Run Code Online (Sandbox Code Playgroud) 我有我的 FormGroup 和一些 FormControles 并且所有这些都是必需的,但我希望只有当我的 component.ts 中的布尔值为 true 时才需要我的两个 FormControles 我试过,ng-required="myboolean"但这没有用。有没有办法做到这一点或解决方法?
//编辑
onButtonClick()
{
this.passwordFormControl = !this.passwordFormControl;
if(this.passwordFormControl)
{
this.passwortButton = "Cancle change Password";
this.benutzerAnlageForm.get('password').setValidators(Validators.required);
}
else
{
this.passwortButton = "Change password";
this.benutzerAnlageForm.get('password').clearValidators();
}
}
<form [formGroup]="MyForm" (ngSubmit)="onMyForm()">
<div *ngIf="passwordFormControl" class = "form-group">
<label for="password">Password</label>
<input formControlName="password" type="password" id="password"
<-- Some more Form Controles that are always required -->
<button type="submit" [disabled]="!MyForm.valid" class ="btn btn-primary">Save</button>
<button *ngIf="edit" type="button" class="btn btn-primary" (click)="onButtonClick()">{{passwortButton}}</button>
</form>
Run Code Online (Sandbox Code Playgroud)
密码 FormControl 是我不希望总是需要的控件。问题是,如果我从密码 FormControl 中删除所需的表单本身,按钮似乎无法识别表单现在再次有效。
我想知道是否可以将输入字段限制为某种格式,例如您想要的尽可能多的数字然后“。” 然后是2位数?这基本上是价格的输入......而且我不想要像模式属性这样的简单验证。我希望用户不能进行错误输入。