0

Good Day developers, im trying to find the way to grap a value an input html tag has from my service class in the same angular class.This input is attached to an ngForm thus is linked to a model interface component in order to validate this form once is submitted.I tried to import the same model interface component in the service class in order to access it from there too, but doesn't work. This is the service:

***variable type model interface***

formSignup: signUpForm = {
    nameUser: '',
}=========>model interface component also imported to service in order to access whichever values user insert in it

***method where in the variable gets updated accesisng the model interface***

 async signUpUser(emailUser: string, passwordUser: string) {
    some code.....

  await responseOk.user.updateProfile({
     displayName:this.formSignup.nameUser});===>this is the value i want to update dynamically from the 
                                                 input value

    more code......
}

Here my html, model and component.ts components related to my issue:

HTML
    <form #submitSign='ngForm' (submit)="signUp(submitSign.value)">
      <input type="text" [(ngModel)]="formSignup.nameUser" name="nameUser" class="form-control" 
      id="nameUser"  placeholder="Name " #nameUser="ngModel"
   </form>

MODEL INTERFACE

export interface signUpForm{
  nameUser?:string,
}

COMPONENT.TS

formSignup: signUpForm = {
    nameUser:'',
    emailUser: '',
    passwordUser: '',
    confirmPasswordUser: '',
    imageUser: '',
  };


  constructor(
    private signUserUp: service){}

  ngOnInit(): void {}

  signUp(value: signUpForm) {
    this.signUserUp
      .signUpUser(value.emailUser, value.passwordUser)
      .then((response) => {

         some code.......
      })
      .catch((error) => error.messages);
}

Any idea about how to improve this ?Thanks in advance!!!

4
  • i'm preferring FormBuilder approach for ReactiveForms, in this way you can better follow to SOLID and DRY practices. But what is really can drive your coding, is writing tests before code it is hard to explain. You need read something or maybe alot about TDD and unit testing in angular. example of code without test stackblitz.com/edit/… Commented May 21, 2020 at 12:53
  • i think in same way you can refactor your component service as in example Commented May 21, 2020 at 12:55
  • video how to step into testing in simple way youtube.com/… Commented May 21, 2020 at 12:57
  • Really Thanks again Radik....i'll take a look on detail about that video you sent me and dive a lil bit more on concepts.thanks for your help!!! Commented May 21, 2020 at 21:29

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.