我想使用 Angular 的接口实现自定义跨字段验证器ValidatorFn。
这是我的代码:(我按照https://angular.io/guide/form-validation#cross-field-validation上提供的步骤进行操作)
import { ValidatorFn, ValidationErrors, FormGroup } from "@angular/forms";
/**
* This validator implements the ValidatorFn Interface from Angular.
*
* @param formGroup- the FormGroup that needs Validation
*
* @returns null if the form is valid, else some {@link ValidatorErrors}
*/
export const CompleteBloodpressureValidator: ValidatorFn = (formGroup: FormGroup) => {
const bloodpressureSys = formGroup.get("bloodPressureSysFormControl");
const bloodpressureDia = formGroup.get("bloodPressureDiaFormControl");
if (bloodpressureSys != null && bloodpressureDia == null || bloodpressureSys == null && bloodpressureDia …Run Code Online (Sandbox Code Playgroud) 有没有办法向一个组件添加多个徽章?
目前我一次只能拥有一个徽章,如下例所示:
<mat-card [ngClass] = "{'custom-card':true}" [matBadge] ="folderContent.length" matBadgePosition="after" matBadgeSize="large" matBadgeColor="accent" matBadgeOverlap="true" >
<mat-card-title>{{folderCaption}}</mat-card-title>
<mat-card-subtitle>{{folderSubtitle}}</mat-card-subtitle>
<mat-card-content>{{folderDescription}}</mat-card-content>
</mat-card>
Run Code Online (Sandbox Code Playgroud) 我有一个父组件,它包含一个名为文档的属性。该属性是一个数组,用于将数组中的文档传递给子组件。
但是,当我将新文档推送到属性文档中时,子组件的视图没有改变。有人能告诉我我在这里做错了什么吗?
这是父组件中属性文档发生更改的位置:
// handle the data that comes back from the dialog
createDialog.afterClosed().subscribe(
data => {
if (data){
// persist vital signs
this.documentService.saveDocument(data.newDocument); // not implemented yet because it makes no sense with non functioning backend
this.documents.push(data.newDocument);
// update the existing document bucket the document belongs to
this.loincToDocumentsMap.get(data.loincCode)?.folderContent.push(data.newDocument);
}
}
);
Run Code Online (Sandbox Code Playgroud)
这是我的子组件:
@Component({
selector: 'document-list',
templateUrl: './document-list.component.html',
styleUrls: ['./document-list.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class DocumentListComponent implements OnInit, OnChanges {
@Input() documents: DocumentReference[] = [];
....
}
Run Code Online (Sandbox Code Playgroud)
这就是我在父组件中使用子组件的地方:
<document-list *ngIf="showListUi" …Run Code Online (Sandbox Code Playgroud)