我有一个表单组件创建一次,重复使用两次共享相同的数据。请看一下代码
//登录组件共享
import { Component, OnInit, Input } from '@angular/core';
import { SignInFormService } from '../../services/sign-in-form-create.service';
import { Auth } from '../../services/auth.service';
@Component({
selector: 'app-sign-in-form',
templateUrl: './sign-in-form.component.html',
styleUrls: ['./sign-in-form.component.css']
})
export class SignInFormComponent implements OnInit {
constructor(private auth: Auth) { }
@Input() userType: string;
ngOnInit() {
this.createForm();
}
createForm() {
this.formGroup = this._formBuilder.group({
username: '',
password: ''
});
}
// Code On编辑器 1。This is an working example works fine without using service 2. This is not working when a service is used
我的问题是组件与服务一起使用时共享相同数据的原因。即使使用该服务,如何仍然保护组件不共享数据?