我有一个对象和代码如下:
SeaWall: ProInfoSeawallBaseDto = new ProInfoSeawallBaseDto();
下面的 html(SeaWallBase 包含属性“final_Crest_Altitude”)
<input type="text" name="final_Crest_Altitude" [(ngModel)]="SeaWall.final_Crest_Altitude">
当我得到值时
console.log(this.SeaWall.final_Crest_Altitude);
网络控制台显示“未定义”。 我对此真的很困惑。我使用了ngModel,它应该被绑定(bind)。我的同事也有同样的问题。 但是,当我将对象名称“SeaWall”更改为“SeaWallBase”时,一切都很好。 “SeaWall”是键名吗?
最佳答案
您的对象未定义,因为您必须在 NgOnInit 方法内初始化对象。
我建议你阅读Angular的生命周期:https://angular.io/guide/lifecycle-hooks
关于angular - 为什么 Angular 在我的情况下无法获得值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47514230/