Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何将文本从输入保存到角度变量?_Html_Angular - Fatal编程技术网

Html 如何将文本从输入保存到角度变量?

Html 如何将文本从输入保存到角度变量?,html,angular,Html,Angular,我试图从我的一个component.html文件中获取文本,并将输入保存到我的一个.ts文件中的方法中的一个变量。你能帮忙吗 home.component.html文件: 如果您使用的是角度,它应该是 ngModel而不是ngModel Username: <input [(ngModel)]="username"><br> Password: <input [(ngModel)]="pass"> 您需要将ng模型更改为ngModel ng型号:-a

我试图从我的一个component.html文件中获取文本,并将输入保存到我的一个.ts文件中的方法中的一个变量。你能帮忙吗

home.component.html文件:
如果您使用的是角度,它应该是

ngModel
而不是
ngModel

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

您需要将ng模型更改为ngModel

ng型号:-angularjs

ngModel:-角度2或更大

Html

Username: <input [(ngModel)]="username"><br>
Password: <input [(ngModel)]="pass">  
<button (click)="login()">Login</button>

谢谢如何将“usr”和“password”的值返回到html而不是写入控制台?为什么要重新运行?它已经存在于HTML中了。你可以把它当作{{user}}{{password}}我实际上返回了不同的文本,我只是想了解如何
Username: <input  [(ngModel)]="username"><br>
Password: <input  [(ngModel)]="pass">  
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);
    }

}
Username: <input [(ngModel)]="username"><br>
Password: <input [(ngModel)]="pass">  
<button (click)="login()">Login</button>
export class HomeComponent implements OnInit {
 public username: String;
 public pass: String;
 public function login() {
 console.log('User Name: ' + this.username);
 console.log('Password: ' + this.pass);
 }
}