Angular 值未在浏览器中更新

Angular 值未在浏览器中更新,angular,Angular,我有一位成员: airline = 'string'; 在我的模板中,我有: <p>{{airline}}</p> 此函数从以下位置调用: this._map.on('SelectionChanged', function (selectionChangedEvent) { if (selectionChangedEvent.selectionChanges.length > 0) { var c = new MapComponent();

我有一位成员:

airline = 'string';
在我的模板中,我有:

<p>{{airline}}</p>
此函数从以下位置调用:

this._map.on('SelectionChanged', function (selectionChangedEvent) {
  if (selectionChangedEvent.selectionChanges.length > 0) {
    var c = new MapComponent();
    c.setValue(selectionChangedEvent);
  } else {

  }
});
当我运行代码时,我确实在setValue函数中看到了
this.airline
的值,但浏览器中的值仍然是
string


为什么不在浏览器中更新?

问题是您正在使用创建新组件

var c = new MapComponent();
因此,您的原始值永远不会更新。您可能想使用

this.setValue(selectionChangedEvent);
相反,您还必须通过更改为lambda函数来保存上下文

this._map.on('SelectionChanged', (selectionChangedEvent) => {

否则,此.setValue将不存在,因为您处于错误的上下文中。

所有函数都在同一个组件中吗?哦,是的,当然。我创建了一个新组件,但从未传递该值。我不确定lambda函数是什么,我在Java中见过它,但没有真正使用它。但是你的建议修正了密码。干杯
this._map.on('SelectionChanged', (selectionChangedEvent) => {