checked-exceptions 相关问题


:主机 ::ng-deep 未将样式应用于材质复选框

我正在尝试为材质多选做一个简单的复选框背景颜色更改。 我尝试过两者都做 .mat-pseudo-checkbox-checked { 背景颜色:#a9a9a9 !重要; } 和 :主持人::ng-de...


选中/取消选中 mat-checkbox 未正确返回 true 或 false

我正在使用 Angular 15 和 Angular Material 14,下面是我用来显示复选框列表的 HTML 代码 我正在 Angular 15 和 Angular Material 14 工作,下面是我用来显示复选框列表的 HTML 代码 <div *ngFor="let control of checkboxArray.controls;let i = index" > <mat-checkbox [formControl]="control" (input)="validateInputs(notificationForm)" [checked]="control.value" (change)="control.checked=$event.checked;onCheckedChange(i);"> {{ checkboxItems[i].name }} </mat-checkbox> </div> 下面是Angular中onCheckedChange函数的代码 onCheckedChange(index: number) { this.sortCheckboxArray(); const checkboxItem = this.checkboxItems[index]; const control = this.checkboxArray.at(index); if (control) { if (control.value) { this.lists.push(checkboxItem.id.toString()); } else { this.lists.pop(checkboxItem.id.toString()); } } this.updateSubscriberGroupsCount(); this.cdr.detectChanges(); } 当我选中复选框时,在这个 onCheckedChange 函数中,control.value 始终返回 false。哪里出了问题?无法理解.. 这是一个工作版本,复选框逻辑工作正常,希望有帮助! 我们需要使用control.value获取表单组,但我们还需要访问内部表单控件,然后获取复选框值! import { CommonModule } from '@angular/common'; import { Component } from '@angular/core'; import { FormArray, FormControl, FormGroup, ReactiveFormsModule, } from '@angular/forms'; import { bootstrapApplication } from '@angular/platform-browser'; import 'zone.js'; import { MatCheckboxModule } from '@angular/material/checkbox'; @Component({ selector: 'app-root', standalone: true, imports: [CommonModule, ReactiveFormsModule, MatCheckboxModule], template: ` <form [formGroup]="form"> <div formArrayName="array"> <div *ngFor="let control of checkboxArray.controls;let i = index" [formGroupName]="i"> <mat-checkbox formControlName="test" style="margin-bottom: 15px;" (change)="onCheckedChange(i);"> {{ checkboxItems[i].name }} </mat-checkbox> </div> </div> </form> `, }) export class App { name = 'Angular'; form = new FormGroup({ array: new FormArray([]), }); lists = []; checkboxItems: any = []; ngOnInit() { this.add(); this.add(); this.add(); } add() { this.checkboxArray.push( new FormGroup({ test: new FormControl(false), }) ); this.checkboxItems.push({ name: 'test' }); } get checkboxArray() { return this.form.get('array') as FormArray; } onCheckedChange(index: number) { // this.sortCheckboxArray(); // const checkboxItem = this.checkboxItems[index]; const control = this.checkboxArray.at(index); if (control) { if (control.value.test) { console.log('checked'); // this.lists.push(checkboxItem.id.toString()); } else { console.log('not checked'); // this.lists.pop(checkboxItem.id.toString()); } } // this.updateSubscriberGroupsCount(); // this.cdr.detectChanges(); } } bootstrapApplication(App); 堆栈闪电战


如何使用布尔属性定义 XML 模式并使用 JS 验证 XML [重复]

我正在寻找一种根据自定义 XML 模式(XSD 文件)解析 XML 字符串的方法,其中包括布尔属性,例如在 HTML 中使用“选中”或“隐藏”等进行的操作: 我正在寻找一种根据自定义 XML 模式(XSD 文件)解析 XML 字符串的方法,其中包括布尔属性,例如在 HTML 中使用“选中”或“隐藏”等进行的操作: <div checked hidden> hello world </div> 我不能只使用 HTML 和 HTML 解析器,因为我希望能够定义自己的允许布尔属性列表。我无法使用纯 XML,因为纯 XML 根本不允许布尔属性。 有什么方法可以利用带有布尔属性的 XML 吗? 我希望能够在 JavaScript 中完成这一切,但如果绝对必要,我可以使用其他东西。 Java 脚本不存在使用 XSD 对客户端 XML 验证的直接支持。我能找到的最好的客户端是这个用于 java 脚本的第三方库:xmljs。还有一个展示其用法的演示:demo. 对于复杂且更强大的验证,我建议在服务器端进行,使用 Node.js 库(例如 libxmljs)或其他语言的支持,例如 Java 库 Xerces 或 C# 中的 XmlSchemaSet 类。


© www.soinside.com 2019 - 2024. All rights reserved.