角度中的输出操作不适用于事件触发



这是代码...

sendData(inp1:Element){
    this.ele.push(inp1['value'])
    this.outData.emit(this.ele);
    console.log(this.ele);
    this.ele += inp1['value'];
    inp1['value'] = "";
}

安慰: [";rjg"]

错误

类型错误:this.ele.push 不是一个函数

如果this.ele没有初始化,那么用空数组初始化它,因为push只处理数组

试试这个:

sendData(inp1:Element){
    if (typeof this.ele == 'undefined') {
       this.ele = []
    }
    this.ele.push(inp1['value'])
    this.outData.emit(this.ele);
    console.log(this.ele);
    this.ele += inp1['value'];
    inp1['value'] = "";
}

最新更新