gpt4 book ai didi

Angular @ViewChild() 错误 : Expected 2 arguments, 但得到 1

转载 作者:太空狗 更新时间:2023-10-29 16:45:55 25 4
gpt4 key购买 nike

尝试 ViewChild 时出现错误。错误是“未提供‘opts’的参数。”

@ViewChild 都给出了错误。

import { Component, OnInit, ElementRef, ViewChild, Output, EventEmitter } from '@angular/core';
import { Ingredient } from 'src/app/shared/ingredient.model';

@Component({
selector: 'app-shopping-edit',
templateUrl: './shopping-edit.component.html',
styleUrls: ['./shopping-edit.component.css']
})
export class ShoppingEditComponent implements OnInit {

@ViewChild('nameInput') nameInputRef: ElementRef;
@ViewChild('amountInput') amountInputRef: ElementRef;
@Output() ingredientAdded = new EventEmitter<Ingredient>();
constructor() {}

ngOnInit() {
}

onAddItem() {
const ingName = this.nameInputRef.nativeElement.value;
const ingAmount = this.amountInputRef.nativeElement.value;
const newIngredient = new Ingredient(ingName, ingAmount);
this.ingredientAdded.emit(newIngredient);
}

}

ts(11,2): error TS2554: Expected 2 arguments, but got 1.

最佳答案

在 Angular 8 中,ViewChild 有两个参数

 @ViewChild(ChildDirective, {static: false}) Component

关于Angular @ViewChild() 错误 : Expected 2 arguments, 但得到 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56704164/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com