Angular nativescript中component.ts和html上变量的双重绑定在特定页面中不起作用。(但仅在登录页面中工作)

Angular nativescript中component.ts和html上变量的双重绑定在特定页面中不起作用。(但仅在登录页面中工作),angular,nativescript,Angular,Nativescript,在这个html组件中,模型会按预期进行更新 login.component.html <FlexboxLayout> <StackLayout class="form" [class.dark]="!isLoggingIn"> <Image src="~/images/logo.png"></Image> <TextField hint="Email Address" keyboardType="ema

在这个html组件中,模型会按预期进行更新

login.component.html

<FlexboxLayout>
    <StackLayout class="form" [class.dark]="!isLoggingIn">
        <Image src="~/images/logo.png"></Image>
        <TextField hint="Email Address" keyboardType="email" autocorrect="false" autocapitalizationType="none" [(ngModel)]="user.email"
        class="input input-border"></TextField>
        <TextField hint="Password" secure="true" [(ngModel)]="user.password" class="input input-border"></TextField>
        <Button [text]="isLoggingIn ? 'Sign in' : 'Sign up'" class="btn btn-primary" (tap)="submit()"></Button>
        <Button [text]="isLoggingIn ? 'Sign up' : 'Back to login'" (tap)="toggleDisplay()"></Button>
    </StackLayout>
</FlexboxLayout>

但在其他页面中,双重绑定似乎不起作用。这是一个编辑页面

html


但是输出不会显示在html页面上。这里有什么不同?是否有缺少的模块需要导入到编辑组件所属的子模块中

您的模块中必须缺少
nativescript FormsModule
,导入它将解决问题。

是的,nativescript forms模块也必须导入子模块中。因此表单模块处理双重绑定?是的,它会。如果仍然没有,您可以共享一个易于调试的游乐场示例。谢谢谢谢你的确认,我添加了它作为答案。
export class LoginComponent implements OnInit {
  user: User;
  isLoggingIn = true;

  constructor(private page: Page, private router: Router, private userService: UserService) {
    this.user = new User();
  }

  ngOnInit() {
    this.page.actionBarHidden = true;
    this.page.backgroundSpanUnderStatusBar = true;
    this.user['email']='someemail@gmail.com';
    this.user['password']='passmein';
  }
}
<FlexboxLayout>
    <StackLayout class="form">
        <Image src="~/images/logo.png"></Image>
        <TextField hint="The make of the car" autocorrect="false" autocapitalizationType="none" [(ngModel)]="car.make"
        class="input input-border"></TextField>
        <TextField hint="Model" autocorrect="false" autocapitalizationType="none" [(ngModel)]="car.model"
        class="input input-border"></TextField>
        <Button text="Save" class="btn btn-primary" (tap)="submit()"></Button>
    </StackLayout>
</FlexboxLayout>
export class UpsertVehicleComponent implements OnInit {
  car:Vehicle;
  new: boolean = true;
  constructor(private page: Page, private router: Router, private route: ActivatedRoute, private vehicleService: VehicleService) { 
    this.car = new Vehicle();
  }

  ngOnInit() {
    var id = this.route.snapshot.paramMap.get("id");
    this.car['make'] ='check';
  }

}