I am new to Angular2 and I have a little problem:
In my Login-Component-HTML, I have two flags that I want to link in two ways: data binding to Login-Component-TypeScript.
This is HTML:
<div class="checkbox"> <label> <input #saveUsername [(ngModel)]="saveUsername.selected" type="checkbox" data-toggle="toggle">Save username </label> </div>
And this is Component.ts:
import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import { Variables } from '../../services/variables'; @Component({ selector: 'login', moduleId: module.id, templateUrl: 'login.component.html', styleUrls: ['login.component.css'] }) export class LoginComponent implements OnInit { private saveUsername: boolean = true; private autoLogin: boolean = true; constructor(private router: Router, private variables: Variables) { } ngOnInit() { this.loginValid = false;
If I click the checkbox, I get the correct value in the controller (component).
But if I change the value, for example, saveUsername in the component, the checkbox will not βreceiveβ the new value.
Therefore, I cannot manipulate the flag from the Component (as I want to do in ngOnInit in the component).
Thanks for your help!
html checkbox angular data-binding typescript
Junias Oct 24 '16 at 9:12 2016-10-24 09:12
source share