问题
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.
来源:https://stackoverflow.com/questions/28629265/angularjs-form-with-and-without-refresh