DEV Community

Prolific12
Prolific12

Posted on

How can I store something written in an input ?

How can I store information written in an input and make whatever is written in the input to show in the browser. These are the codes I wrote for the html and the typescript

This is the html code

<form action="">
    <h1>Add User Information</h1>
    <input name="userName" (input)="userDetails()" [(ngModel)]="userName" type="text"><br>
    <input (input)="userDetails()" type="email" [(ngModel)]="email" name="email" placeholder="Email"><br>
    <input (input)="userDetails()" type="text" [(ngModel)]="course" name="course" placeholder="Course"><br>
    <input (input)="userDetails()" type="text" [(ngModel)]="location" name="Location" placeholder="Enter Your Location"><br>
    <button (click)="addUser()">Add User</button>
    <div *ngFor = "let user of allUser">
        <h3>{{user}}</h3>
    </div>
</form>
Enter fullscreen mode Exit fullscreen mode

This is the typescript code

  public userName:string = "";
  public email:string = "";
  public course:string = "";
  public location:string = "";
  public allUser:Array<object> = [{userName: this.userName}, {email: this.email}, {course: this.course}, {location: this.location}];
  userDetails(){
    console.log(this.allUser);
  };
  addUser(){
    this.allUser.push(this.userArray);
    console.log(this.allUser);
  };
Enter fullscreen mode Exit fullscreen mode

I'm new to Angular, so i don't really understand it yet

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (1)

Collapse
 
vijayalashmy profile image
Viji_Pykara

Do you want to store the values temporarily? When the browser cache is cleared or the page is refreshed, do you want the values to be deleted?

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more