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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You won't be able to submit form data without a page refresh, unless you submit the data asynchronously via XHR.
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.
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.