Я пытаюсь установить простую шаблонную проверку формы с # password = "ngModel" во входном файле, когда я читаю password.length, я получаю неопределенное значение и не понимаю, почему
Мой угловойФорма:
<form #f="ngForm">
<input class="form-control" placeholder='a' type="text" name="password" id="password" [(ngModel)]="renewPasswordData.password"
#password="ngModel">
{{password.length == null}} //<-- returns true
<button [disabled]="password.length == 0" class="btn btn-success btn-block"> //<-- it not works
{{"changePassword.change" | translate}}
</button>
</form>
Файл TS:
import { Router } from '@angular/router';
import { Component, OnInit, AfterViewInit } from '@angular/core';
import { RenewPassword } from 'src/app/models/others/RenewPassword';
@Component({
selector: 'app-change-password',
templateUrl: './change-password.component.html',
styleUrls: ['./change-password.component.css']
})
export class ChangePasswordComponent implements OnInit {
renewPasswordData = new RenewPassword("12", "");
constructor(private router: Router) {
console.log(this.renewPasswordData.password.length) //<-- return 2 (correct)
}
ngOnInit() {
}
}
Модель:
export class RenewPassword {
constructor(
public password: String,
public rePassword: string
) {
}
}
Мой импорт ngModule
imports: [
HttpClientModule,
BrowserModule,
AppRoutingModule,
FormsModule,
ReactiveFormsModule
],
stackblitz: https://stackblitz.com/edit/angular-uzjqdq