小编sta*_*low的帖子

角@ViewChild()错误:预期有2个参数,但得到1个

尝试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);
  }

}
Run Code Online (Sandbox Code Playgroud)

ts(11,2):错误TS2554:预期有2个参数,但得到1。

typescript angular

118
推荐指数
4
解决办法
5万
查看次数

标签 统计

angular ×1

typescript ×1