Anonymous
Доступ к входному элементу, который динамически генерировал либо с помощью его идентификатора, либо Templatereference
Сообщение
Anonymous » 23 сен 2025, 19:06
Я должен добавить и удалить элементы продукта, получив либо идентификатор входного элемента, либо через ссылку на шаблон входного элемента. Поскольку мне нужны другие действия, получив доступ к входному элементу. Пожалуйста, избегайте добавления нового свойства в массив входных продуктов.
ниже упоминается выход
file.
Код: Выделить всё
export class ProductsComponent implements OnInit {
@ViewChildren('quantityreference') dynamicElements!: QueryList;
productlists = JSON.parse(`[
{
"productId": "T00110",
"productName": "first",
"productPrice": "0",
"gst":"20"
},
{
"productId": "T000",
"productName": "Punnakuuu",
"productPrice": "40",
"gst":"20"
},
{
"productId": "T1111",
"productName": "Thenkaai Punnaku",
"productPrice": "40",
"gst":"18"
},
{
"productId": "MT1",
"productName": "Mattu Theevanam",
"productPrice": "55",
"gst":"18"
},
{
"productId": "CP1",
"productName": "m Punnaku",
"productPrice": "55",
"gst":"12"
},
{
"productId": "CP2",
"productName": "ell Punnaku",
"productPrice": "22",
"gst":"12"
}]`
);
constructor() { }
purchasedProudct = new Purchasedproduct("", "", 0, 0, "");
selectedquantity: number = 0;
@ViewChildren('quantityreference', { read: ElementRef }) products!: QueryList;
ngOnInit(): void {
}
increment(indexvalue: number) {
const item = this.productlists[indexvalue];
this.selectedquantity++;
}
decrement(indexvalue: number) {
const item = this.productlists[indexvalue];
if (this.selectedquantity > 0) {
this.selectedquantity--;
}
}
}
< /code>
my .html file < /h2>
0">
[h4]{{product.productName}}[/h4]
Rs. {{product.productPrice}}
remove
add
Кто -нибудь пытается решить это.
Подробнее здесь:
https://stackoverflow.com/questions/797 ... d-or-templ
1758643563
Anonymous
Я должен добавить и удалить элементы продукта, получив либо идентификатор входного элемента, либо через ссылку на шаблон входного элемента. Поскольку мне нужны другие действия, получив доступ к входному элементу. Пожалуйста, избегайте добавления нового свойства в массив входных продуктов. ниже упоминается выход file.[code]export class ProductsComponent implements OnInit { @ViewChildren('quantityreference') dynamicElements!: QueryList; productlists = JSON.parse(`[ { "productId": "T00110", "productName": "first", "productPrice": "0", "gst":"20" }, { "productId": "T000", "productName": "Punnakuuu", "productPrice": "40", "gst":"20" }, { "productId": "T1111", "productName": "Thenkaai Punnaku", "productPrice": "40", "gst":"18" }, { "productId": "MT1", "productName": "Mattu Theevanam", "productPrice": "55", "gst":"18" }, { "productId": "CP1", "productName": "m Punnaku", "productPrice": "55", "gst":"12" }, { "productId": "CP2", "productName": "ell Punnaku", "productPrice": "22", "gst":"12" }]` ); constructor() { } purchasedProudct = new Purchasedproduct("", "", 0, 0, ""); selectedquantity: number = 0; @ViewChildren('quantityreference', { read: ElementRef }) products!: QueryList; ngOnInit(): void { } increment(indexvalue: number) { const item = this.productlists[indexvalue]; this.selectedquantity++; } decrement(indexvalue: number) { const item = this.productlists[indexvalue]; if (this.selectedquantity > 0) { this.selectedquantity--; } } } < /code> my .html file < /h2> 0"> [h4]{{product.productName}}[/h4] Rs. {{product.productPrice}} remove add [/code] Кто -нибудь пытается решить это. Подробнее здесь: [url]https://stackoverflow.com/questions/79772831/access-the-input-element-that-dynamically-generated-either-using-its-id-or-templ[/url]