Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.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
Forms 向Angular 2应用程序提交表单_Forms_Angular - Fatal编程技术网

Forms 向Angular 2应用程序提交表单

Forms 向Angular 2应用程序提交表单,forms,angular,Forms,Angular,向Angular 2应用程序提交表单的最佳方式是什么?也就是说,从一个非角度的网站,到一个角度的应用程序 你不能简单地用method=“GET”将应用程序作为动作URL,因为Angular 2使用“矩阵URL符号”,浏览器会将表单字段添加为常规参数(?=,&=) 例如,假设URL是Angular 2应用程序,此方法不起作用: <form method="GET" action="http://myangular2app.com/search;"> <input name

向Angular 2应用程序提交表单的最佳方式是什么?也就是说,从一个非角度的网站,到一个角度的应用程序

你不能简单地用
method=“GET”
将应用程序作为动作URL,因为Angular 2使用“矩阵URL符号”,浏览器会将表单字段添加为常规参数(?=,&=)

例如,假设URL是Angular 2应用程序,此方法不起作用:

<form method="GET" action="http://myangular2app.com/search;">
    <input name="q">
    <input type="submit" value="Go">
</form>


浏览器将导航到类似
http://myangular2app.com/search;?q=mysearch
何时需要搜索
http://myangular2app.com/search;q=mysearch
(无问号)

您可以使用
ngModel
指令使用双向绑定

<input name="q" [(ngModel)]='name'>
在通话中使用此选项:

this.http.get("http://myangular2app.com/search;q="+mysearch)

如果你是Angular2的新手,我建议你花点时间看看


这将引导您创建一个简单的web应用程序,其中包括表单、数据绑定和HTTP请求

抱歉,这根本不能回答问题。好的,让我澄清一下。如果使用表单模块,则不必担心angulars矩阵URL符号
this.http.get("http://myangular2app.com/search;q="+mysearch)