Change attribute of a component in another non-angular component

2

I have two components:

Registration and Login

In the RecordComponent I have this anchor:

<a id="titleClient">Already have a account? Click here</a>

I need when the user clicks the anchor change in the login component the attribute of my class "already_client" to true:

export class LoginComponentimplements OnInit {
  already_client: boolean
  ...
}

I thought of doing with input property but I use the router-outlet to show the components, I can not use, for example:

How can I do this?

Thank you

@Edit:

How did it work for me:

My login component:

  ngOnInit() {
    this.handleSubscriptions()
  }

  public handleSubscriptions() {
    this.subscription = this.registrarService.params.subscribe(
      action => {
        if(action !== undefined){
          this.usuario.cliente= action.action
        }
      }
    )
  }

Register component:

  setPossuiConta(){
    this.registrarService.setParameters(true);
    this.router.navigate(['/login']);
  }

Service:

 private cliente: BehaviorSubject<any> = new BehaviorSubject<any>({} as any);
  public params = this.cliente.asObservable().pipe(distinctUntilChanged());

  public setParameters(possui_conta: boolean) {
    this.cliente.next({action: possui_conta});
  }
    
asked by anonymous 04.12.2018 / 12:18

1 answer

3

Create a service, add the Subject and also a method to issue the value.

alreadyClientChange: Subject<boolean> = new Subject<boolean>();

  changeValue(){
    this.alreadyClientChange.next(true);
  }

Inject the service into the RecordComponent and add a method for when the user clicks the link

meuMetodo(){
 myService.changeValue();
}

Inject the service into LoginComponent and sign up to get and change the value of already_client

ngOnInit() {
  myService.alreadyClientChange.subscribe(res => {
    already_client = res;
  });
}
    
04.12.2018 / 13:00