如何在其他函数中获取deviceValue?

时间:2019-06-08 14:34:19

标签: angular

状态:字符串=“”;

setStatus(deviceValue) {
this.status = deviceValue.valueOf();
return this.status;
}

update(value: string, index: number, item: number) {

this.setStatus(???)    

alert(this.status);
if (this.status == '1') {something}
else if (this.status == '2') {something}
}

在这种情况下,如何获取deviceValue并放入update()?

1 个答案:

答案 0 :(得分:0)

我已将其重写以解释可能缺少的内容。

public status: TYPE; // you define `status` and its type

// this sets `status` to deviceValue.valueOf() when selection is made
setStatus(deviceValue: type) {
    this.status = deviceValue.valueOf();
}

// use your global status
update(value: string, index: number, item: number) {
    if (this.status == '1') {
        something
    } else if (this.status == '2') {
        something
    }
}

模板:

<select id="portOrigin" (change)="setStatus($event.target.value)">
  ...
</select>