How to save text from input to variable in angular?

Chris Dunn

I'm trying to take text from one of my component.html files and save the input to a variable in a method in one of my .ts files. Can you help?

home.component.html file:

Username: <input ng-model="username"><br>
Password: <input ng-model="pass">  
<button (click)="login()">Login</button>

home.component.ts file:

export class HomeComponent implements OnInit {

    login()
    {
     const usr= {{username}};
     const password={{pass}};
     print("user is"+usr " Password is"+password);

    }

}
Sajeetharan

If you are using angular it should be

ngModel instead of ng-model

Username: <input  [(ngModel)]="username"><br>
Password: <input  [(ngModel)]="pass">  

and in component.ts

export class HomeComponent implements OnInit {
    username : string;
    password : string;

    login()
    {
     const usr= this.username;
     const password= this.password;
     console.log("user is"+usr " Password is"+password);
    }

}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Save user input from Angular ReactiveForm in variable

Flutter : how do i save input from a text field to an int variable?

Windows: How to save a variable -(input: path) to text file

How to get an input from user in Pygame and save it as a variable?

How to input value from user and save in variable wxDev-C++

how to save input from e.get in a variable (python, tkinter)

How to save all user input from for loop into text file

How to save string from input to existing text JAVASCRIPT

Angular- How to prevent text in input from showing if input is invalid

Save text input to a variable in a kivy app

How to save the text from a .txt file as a c++ variable

How do I get a variable from a text input in tkinter?

save input from text file to array

Save input from html to text file problem

tkinter - How can you use get() to save the input in a Scrolled Text widget to a variable

How to save a user's input as a variable?

How to remove text auto save in html input

How do you add text to a text box with an input field and delete it from the text box with Angular JS?

Is there good way to save text input from tkinter Text widget

How to save user input from CHOICE command to a variable to be used later in the errorlevel

How to copy the input field from a user when a button is pressed and save it to a variable

How to save a users input from a javascript pop up form in to a php variable?

Debian - How to save variable in a text file / Zenity

How do I use a variable from a text input as the text for a Label (kivy)

Get text from div, add some more text, save as variable

How to get input from fingerprint scanner and save it

How to save user input from Alert Dialog?

Is there a way to save the input (float) from a variable created in a user interface in Python?

Save edited data from the input text and remove readOnly attribute