HTML5 type =“range”this.value返回undefined

时间:2018-02-23 14:43:49

标签: html5 angular typescript rangeslider

我正在尝试进行范围输入,但是当我尝试将其传递给我的函数时,它返回undefined:

HTML:

<div class="slidecontainer">
    <label>Setpoint</label>
    <p>{{channel.setPoint}}</p>
    <div>
         <p>5</p>
         <p>30</p>
    </div>
    <input type="range" min="5" max="30" value="50"  step="0.5" class="slider"
        [(ngModel)]="channel.setPoint" (onchange)= "putSetpoint(channel, this.value)">
    <br>
</div>

TS文件:

putSetpoint(cb: Channel, value: number) {
    console.log(value);
    cb.setpoint = value;
    this.homedata.setpointChannel(cb);
}

1 个答案:

答案 0 :(得分:0)

this.value没有引用任何内容,您必须告诉Angular您指的是input的值:

 <input #inputRange type="range" min="5" max="30" value="50"  step="0.5" class="slider"
        [(ngModel)]="channel.setPoint" (onchange)= "putSetpoint(channel, inputRange.value)">