0

In this html component, the model gets updated as expected.

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>

login.component.ts

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']='[email protected]';
    this.user['password']='passmein';
  }
}

enter image description here

But double binding doesn't seem to be working in other pages. It's an edit page.

html

<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>

tns

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';
  }

}

But the output wouldn't show up on the html page. What is different here? Is there some missing module that needs to be imported into the submodule the edit component belongs to?

5
  • 1
    Yes, the nativescript forms modules has to be imported in your submodules too. Commented Feb 9, 2019 at 10:19
  • So the forms module handle the double binding? Commented Feb 9, 2019 at 10:30
  • Yes, it would. If it still doesn't, you may share a Playground Sample which could be easy to debug. Commented Feb 9, 2019 at 13:00
  • No it worked. Thanks! Commented Feb 9, 2019 at 13:06
  • Thanks for confirming, I added it as answer. Commented Feb 9, 2019 at 13:11

1 Answer 1

1

You must be missing NativeScriptFormsModule in your module, importing it will solve the problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.