Change attribute of one component into another component at the angle

Asked

Viewed 556 times

2

I have two components:

Registration and Login

In the Registry I have this anchor:

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

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

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

I thought to do with input Property but I use the router-outlet to show the components, I can not use, for example:

How can I do?

Thank you

@Edit:

How it worked 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:

  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});
  }
  • You must pass the value to the login component using the Developer @Input, Please provide more details your question

  • Take a look at my answer https://answall.com/questions/305588/sharedata

1 answer

3


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

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

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

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

meuMetodo(){
 myService.changeValue();
}

Inject the service also in Logincomponent and sign up to get and change the value of already_client

ngOnInit() {
  myService.alreadyClientChange.subscribe(res => {
    already_client = res;
  });
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.