使用 Angular Material 对话框弹出时,我发现以下错误。单击“添加产品”按钮时,发现以下错误
阻止在元素上使用 aria-hidden,因为其后代保留了焦点。焦点不能对辅助技术用户隐藏。避免在焦点元素或其祖先上使用 aria-hidden。...
我的 stackblitz 链接是 https://stackblitz.com/github/reegan2024/mygithubrepo?file=README.md
有人可以帮忙吗
使用 Angular Material 对话框弹出时,我发现以下错误。单击“添加产品”按钮时,发现以下错误
阻止在元素上使用 aria-hidden,因为其后代保留了焦点。焦点不能对辅助技术用户隐藏。避免在焦点元素或其祖先上使用 aria-hidden。...
我的 stackblitz 链接是 https://stackblitz.com/github/reegan2024/mygithubrepo?file=README.md
有人可以帮忙吗
我有一个带有嵌套对象的对象。我尝试使用 Angular 的 ngFor 指令在 html 中显示。但我得到了多次的结果。在我的对象下面
productlists = [
{
productname: 'orange', price:
[{ small: 20 }, { medium: 30 }, { large: 40 }], gst: 12
},
{
productname: 'lemon', price:
[{ small: 40 }, { medium: 80 }, { large: 102 }], gst: 20
},
{
productname: 'apple', price:
[{ small: 40 }, { medium: 80 }, { large: 102 }], gst: 20
}
];
html 代码是
<div style="margin-left: 20rem;">
<div *ngFor="let product of productlists" >
<p style="color: blue;">Product Name {{product.productname}}</p>
<div *ngFor="let productprice of product.price">
Product Price
<p>Small: {{productprice.small}}</p>
<p>Medium: {{productprice.medium}}</p>
<p>Large: {{productprice.large}}</p>
</div>
<p>Product GST {{product.gst}}</p>
</div>
</div>
请帮我正确显示
我有两个单选按钮。当我选择“部分付款”时,输入元素 formControlName="paidamount" 将与 <div class="formGroup" 一起显示在屏幕上。我使用了绑定,但这不起作用。
<mat-radio-group aria-label="Select an option" formControlName="fullypaid" [(ngModel)]="fullypaidvalue">
<mat-radio-button value="true" [checked]="true">Fully Paid</mat-radio-button>
<mat-radio-button value="false">Partially Paid</mat-radio-button>
</mat-radio-group>
<p>{{fullypaidvalue}}</p>
<div class="formGroup" [class.d-none]="fullypaidvalue">
<label for="paidamount" class="form-label" style="margin-top: 10pt;">Paid Amount</label>
<input type="text" class="form-control form-control1" id="paidamount" formControlName="paidamount"
placeholder="paidamount" name="paidamount" style="margin-left: 20pt;">
</div>
我的 stackblitz 链接是 https://stackblitz.com/github/reegan2024/mygithubrepo?file=README.md
有人可以帮帮我吗
我正在 Angular 项目中生成 pdf。在这里我将其用作<app-pagedesign>
子组件<app-root>
,产品列表在此处提交。提交表单后生成 pdf。一切正常。但是当我单击“联系人”并返回“产品”链接时,pdf 生成时没有提供任何输入。即它采用了之前提交的值。我认为这是由于子组件的初始化造成的。但我无法解决这个问题。有人能帮我解决这个问题吗?
我的 stackblitz 链接是 https://stackblitz.com/github/reegan2024/mygithubrepo?file=README.md
我正在使用带有动态字段(产品名称)的反应式表单。如果提交表单时未填写产品名称,则可能会引发验证错误。
但是当我单击“添加”按钮时,每次输入新内容时都会出现“输入产品名称”错误(formControlName="productname")。我还提供了 stackblitz 链接,请有人提供解决方案
https://stackblitz.com/github/reegan2024/mygithubrepo?file=src%2Fapp%2Fapp.component.html
我正在开发计费模块,该模块具有动态添加的输入字段。在这里,我使用自动完成搜索过滤器来动态添加输入字段(产品名称)。
但如果有一个产品名称字段,自动完成搜索工作正常。当我添加多个产品名称详细信息时,只有最后添加的字段可以正常工作。当我尝试更改以前的产品名称字段时,它不起作用。
下面是html代码
<form [formGroup]="productFormarray" (ngSubmit)="onSubmit()">
<div class="reg-right">
<div class="formGroup">
<label for="customername" class="form-label">Customer Name</label>
<input type="text" class="form-control" id="customername" placeholder="Customer Name"
formControlName="customername">
</div>
<div class="formGroup" class="formGroup" formArrayName="productdetails">
<div class="table-responsive">
<table class="table table-bordered" style="margin-top: 20px;">
<thead>
<tr>
<td style="width:40%">
Product Name
</td>
<td style="width:15%">
Quantity
</td>
<td style="width:15%">
Price
</td>
<td style="width:15%">
Gst
</td>
<td>
</td>
</tr>
</thead>
<tr *ngFor="let product of productdetailsarray.controls; let i=index" [formGroupName]="i">
<td>
<div class="formGroup">
<input formControlName="productname" matInput type="text" [matAutocomplete]="auto"
class="form-control" [formControl]="formcontrol" />
<mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let product of filteroptions | async" [value]="product">
{{product}}
</mat-option>
</mat-autocomplete>
</div>
</td>
<td>
<div class="formGroup">
<select class="form-control" id="quantit" formControlName="quantit" name="quantit">
<option *ngFor="let quantity of quantitylist" [ngValue]="quantity">
{{quantity}}
</option>
</select>
</div>
</td>
<td>
<div class="formGroup">
<input type="text" class="form-control" id="price" formControlName="price"
placeholder="Price " readonly name="price">
</div>
</td>
<td>
<div class="formGroup">
<input type="text" class="form-control" id="gst" formControlName="gst" placeholder="Gst"
name="gst" readonly>
</div>
</td>
<td>
<a type="button" class="form-control btn btn-primary" style="background-color: red;"
(click)="removeProduct(i)">Remove (-)</a>
</td>
</tr>
</table>
</div>
<a type="button" class="btn btn-secondary" style="background-color: green;"
(click)="addNewProduct()">Add(+)</a>
<br />
</div>
<br />
<br />
<div class="row">
<div class="col-md-6">
</div>
<div class="col-md-6">
<div class="formGroup">
<label for="totalprice" class="form-label" style="margin-top: 10pt;">Total Product Price</label>
<input type="text" class="form-control form-control1" id="totalprice" formControlName="totalprice"
placeholder="totalprice" name="totalprice" style="margin-left: 20pt; float:right" readonly>
</div>
</div>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
下面是打字稿代码
import { Component, OnInit, ViewChild } from '@angular/core';
import { FormGroup, FormControl, FormArray, FormBuilder, NgForm, Validators } from '@angular/forms'
import { EMPTY, Observable, map, of, startWith } from 'rxjs';
import { toArray } from 'rxjs';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit
{
productFormarray: any;
quantitylist = [0.5, 1, 1.5];
items!: FormArray;
totalGstPrice: number = 0;
totalProductPrice: number = 0;
productlist = [{ productname: "apple", price: 10, gst: 10 }, { productname: "orange", price: 20, gst: 12 }, { productname: "lemon", price: 30, gst: 20 }];
productlistss = ['apple', 'lemon', 'orange'];
filteroptions!: Observable<string[]>;
formcontrol = new FormControl('');
constructor(private fb: FormBuilder) {
this.productFormarray = new FormGroup({
customername: new FormControl('', Validators.required),
productdetails: new FormArray([]),
remember: new FormControl('true'),
totalprice: new FormControl(''),
})
}
private _filter(value: string): string[] {
const searchvalue = value.toLocaleLowerCase();
return this.productlistss.filter(option => option.toLocaleLowerCase().includes(searchvalue));
}
onProductChange(selectedProductName: string, index: number) {
const selectedProduct = this.productlist.find(
(product) => product.productname === selectedProductName
);
if (selectedProduct) {
const productDetailsArray = this.productFormarray.get(
'productdetails'
) as FormArray;
if (productDetailsArray && productDetailsArray.at(index)) {
const quantityControl = productDetailsArray.at(index).get('quantit');
if (quantityControl) {
const quantity = quantityControl.value;
const price = selectedProduct.price * quantity;
const priceControl = productDetailsArray.at(index).get('price');
if (priceControl) {
priceControl.setValue(price);
}
}
}
}
}
onQuantityChange(selectedQuantity: number, index: number) {
const productDetailsArray = this.productFormarray.get(
'productdetails'
) as FormArray;
if (productDetailsArray && productDetailsArray.at(index)) {
const productNameControl = productDetailsArray.at(index).get('productname');
if (productNameControl) {
const selectedProductName = productNameControl.value;
const selectedProduct = this.productlist.find(
(product) => product.productname === selectedProductName
);
if (selectedProduct) {
const price = selectedProduct.price * selectedQuantity;
const priceControl = productDetailsArray.at(index).get('price');
if (priceControl) {
priceControl.setValue(price);
}
}
}
}
}
onPriceChange(selectedQuantity: number, index: number) {
const productDetailsArray = this.productFormarray.get('productdetails') as FormArray;
if (productDetailsArray && productDetailsArray.at(index)) {
const productNameControl = productDetailsArray.at(index).get('productname');
if (productNameControl) {
const selectedProductName = productNameControl.value;
const selectedProduct = this.productlist.find(
(product) => product.productname === selectedProductName
);
if (selectedProduct) {
const priceControl = productDetailsArray.at(index).get('price');
const gst = ((selectedProduct.gst * priceControl?.value) / 100);
const gstControl = productDetailsArray.at(index).get('gst');
gstControl?.setValue(gst);
}
}
}
}
addNewProduct() {
this.items = this.productFormarray.get('productdetails') as FormArray;
const newProduct = this.createNewProduct();
this.items.push(newProduct);
const indexvalue = this.items.length - 1;
this.productFormarray.get('productdetails').controls[indexvalue].get('quantit').setValue(this.quantitylist[1]);
const productNameControl = newProduct.get('productname');
if (productNameControl) {
this.filteroptions = productNameControl.valueChanges.pipe(startWith(''), map(value => this._filter(value)));
console.log('filteroption--- = ' + this.filteroptions);
productNameControl.valueChanges.subscribe(selectedProductName => {
this.onProductChange(selectedProductName, indexvalue);
}
);
}
const quantityControl = newProduct.get('quantit');
if (quantityControl) {
quantityControl.valueChanges.subscribe(selectedQuantity => {
this.onQuantityChange(selectedQuantity, indexvalue);
})
}
const priceControl = newProduct.get('price');
if (priceControl) {
priceControl.valueChanges.subscribe((selectedProductName) =>
this.onPriceChange(selectedProductName, indexvalue)
);
}
}
createNewProduct(): FormGroup {
return new FormGroup({
productname: new FormControl('', Validators.required),
quantit: new FormControl('1', Validators.required),
price: new FormControl('', Validators.required),
gst: new FormControl('', Validators.required)
})
}
removeProduct(index: any) {
this.items = this.productFormarray.get('productdetails') as FormArray;
this.items.removeAt(index);
}
get productdetailsarray() {
return this.productFormarray.get('productdetails') as FormArray;
}
ngOnInit() {
this.addNewProduct();
}
onSubmit() {
}
}
有人可以帮助我吗?