我想通过以下方式使用Angularjs表单指令:如果它在/home中重定向到/search/term,并且如果已经在/search进程中而无需页面刷新,则只需更改位置即可.我知道怎么做,但是我不知道如何编写在两个示例中都可以使用的可重用代码.
I would like to use an Angularjs form directive in the following way: if it's in /home redirect to /search/term and if already in /search process the submit without page refresh just changing the location. I know how to do both, but I don't know how to write a reusable code which works in both examples.
推荐答案除非刷新页面,否则将无法提交表单数据,除非您通过XHR异步提交数据.
You won't be able to submit form data without a page refresh, unless you submit the data asynchronously via XHR.
听起来您正在/home通过HTTP POST或GET同步提交,这将导致页面刷新.您将需要编写一些Angular代码,以从表单控件中获取值并通过XHR POST或GET提交.
It sounds like you are submitting synchronously via HTTP POST or GET at /home, which would result in a page refresh. You will need to write some Angular code to take the values from the form controls and submit it via XHR POST or GET.
这是两种完全不同的方法,因此可能很难编写可重用的东西. 本质上,一种是普通的旧HTML方法,而另一种则需要更多的复杂性和一些Javascript.
It's two quite different approaches so may be difficult to write something reusable. Essentially one is a plain old HTML methodology whereas the other requires a a bit more sophistication and some Javascript.
更多推荐
带有和不带有刷新的AngularJS表单
发布评论