双向绑定不适用于userModel

时间:2019-01-29 03:26:40

标签: angular

在文本框上键入时,Angulars表单值会更改,但userModel值不会更改,始终显示“ Vino”,“ New street”,“ Cairo”,“ Alaska”,“ 343343”,“ vino @ xyz”。 com','53433234','',userModel值中为true。

1   2   3

1 个答案:

答案 0 :(得分:0)

在app.component.ts文件中,将userModel作为数组,应将其声明为对象。像这样:

this.userModel = {

}
  

在app.component.ts文件中,您应该导入用户类,将userModel的类型指定为User,然后在构造函数或ngOnInit()方法中实例化具有相应属性的User类:

import { User } from './user'; //(this will be the path as per your file structure)

userModel: User; // userModel like this

constructor() {
  // assigning initial value to userModel
  this.userModel = new User(
    this.name, "street", "city", "start", 1234, "timePreference", true
  );

  console.log(this.userModel);
}

这是一个在线示例:CLICK HERE