Search code examples
angularcookiesinputweb-applications

Angular -> Put Username from Cookie into Inputfield


I have a Webapplication with oAuth, the Webapplication contains a Inputifeld for the Users loginName. The Loginname also is in the Cookie from the oAuth. I now want to get that username from the Cookie and put it into the inputfield so that the User doesen't has to type it in by themselves. But the user should also have the Option to change the Input if he wants to.

This is my Inputfield:

<div class="input-field-userName">
    <div class="input-field input-oneline center-block" data-init="auto" style="width: 20%;">
      <input
        [formControlName]="homeForm.Username"
        [name]="homeForm.Username"
        type="text"
        id="userName"
        placeholder="userName"
        ngModel pattern="^t\w{4,9}$">
    </div>
  </div>

Solution

  • you can set the default value during initialization of the form . The default username can be read from cookie

    `registerForm = new FormGroup({
     userName: new FormControl('alvic'),  // add default value
     `