我在Angular 5中遇到了“预期有2个参数,但有1个”错误。
这是我的代码,使带有前缀的居中输入字段成为可能。问题是下面的行“ this.resizable(this.classElements [i]);”
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent implements OnInit {
classElements = document.getElementsByClassName('myinput');
resizable (el, factor) {
let int = Number(factor) || 7.7;
function resize() {el.style.width = ((el.value.length + 1) * int) + 'px'}
let e = 'keyup,keypress,focus,blur,change'.split(',');
for (let i in e) el.addEventListener(e[i],resize,false);
resize();
}
ngOnInit() {
for (let i=0; i < this.classElements.length; i++) {
this.resizable(this.classElements[i]);
}
}
}
.myinput {
min-width:60px!important;
max-width:99.99%!important;
transition: width 0.25s;
}
<div class="input-group prefix">
<span class="input-group-addon">Prefix</span>
<input class="myinput" type="text" />
</div>
答案 0 :(得分:2)
您忘记在resizable
函数中传递第二个参数。
this.resizable(this.classElements [i],factorData);