如何在Angular 4+中更新地图现有键的值

时间:2018-10-29 01:36:46

标签: angular dictionary angular6

有什么方法可以更新角度为4+的已创建键值对映射的值。

说我有:

testMap: Map<number, string> = new Map<number, string>();

ngOnInit() {
    this.testMap.set(1, "A");
    this.testMap.set(2, "B");
    this.testMap.set(3, "C");
    this.testMap.set(4, "D");
    this.testMap.set(5, "E");
}

changeValue(id){
    //id is the one of the keys of the map whose value needs to be altered
    //let say (id=3)
    this.testMap.put(id,"ChangedValue"); //PUT is from java
}

1 个答案:

答案 0 :(得分:2)

您可以设置:

this.testMap.set(id, "ChangedValue")