login.component.html
<form class="login-form" name="login-form" #loginForm="ngForm" (ngSubmit)="checkLogin(loginForm)">
<input type="text" placeholder="Username" name="userId" [(ngModel)]="userModel.userId" #userId="ngModel" required />
<input type="password" name="userPwd" placeholder="Password" [(ngModel)]="userModel.userPwd" #userPwd="ngModel" required
/>
</form>
login.component.ts
checkLogin(loginForm) {
let loginFormData = loginForm.value;
this.sessionTime = Date.now();
loginFormData.sessionTime = this.sessionTime;
...
...
...
}
admin.component.ts
export class AdminComponent implements OnInit{
@ViewChild(LoginComponent) child: LoginComponent;
ngAfterViewInit() {
console.log(this.child.checkLogin()); //as agruments is not passed am getting error
}
如果我通过参数说CheckLogin(表格:登录Form(获取错误但是以上方式,我可以共享一个从一个组件到另一个组件的数据,尝试共享样本文本。问题与参数共享方法。任何人都可以帮助我解决解决方案。
您可以将登录形式用作控制器的公共字段。这样,您的方法CheckLogin将不会采用任何参数,您可以在没有错误的情况下调用它。