Angular blocking submit form GET

6

I have a form where I send a query to the current url, via parameters GET . For example, I have url/teste , when sending the query through this form, it will be url/teste?term=minha+consulta .

I did not use Angular in this part because it was ready, so the form already existed before.

When I put the angle, this form stopped submitting.

Exemplifying my scenario:

<body ng-app="my_app">
    <!-- esse input manda para mesma página uma pesquisa GET, por isso não usei "ACTION" -->
    <form id="form-pesquisa">
        <input type="search" name="term" />
        <button type='submit'>Pesquisar</button>
    </form>


    <!-- uso esse formulário no Angular -->
    <form ng-controller="UserCreateController">
        <input type='text' name="email" ng-model="user.email" />
        <input type='password' name="password" ng-model="user.password" />
    </form>
</body>

I noticed that the angle is adding the ng-submitted classes to this form when I submit the submission.

I would like to know how I can use a form, within the context of ng-app , but can make a submission via GET .

Does the angle really block these requests? How to get around this?

    
asked by anonymous 08.08.2016 / 17:08

2 answers

10

AngularJS blocks the default action of the form unless the action is specified in the <form> . Then just add action referencing the page itself:

<form ng-controller="UserCreateController" action=".">
   ...
</form>

In this case, when you use . , it is understood by the browser that you are referencing the page itself.

    
12.08.2016 / 00:46
2

By replying from Vanderlei , we concluded that the problem was the lack of action in the form, where you wanted to submit a data submission to the server.

In fact, you can use the form without action usually in HTML . Whenever you do this, the form will be submitted to the current url.

However, with the lack of action , when you use Angular, it blocks any submissions. And I explain why:

But why without action did not work, as it usually works without AngularJS?

According to AngularJS documentation :

  

For this reason, Angular prevents the default action (form submission to the server) unless the element has an attribute attribute specified

What translating is:

  

For this reason, Angular prevents the default action (sending the form to the server) unless the action is specified in the element.

So even if you intend to use the form to submit a submission to your own page, you must use the action attribute, because by default, the angle, in the absence of that attribute, uses preventDefault to avoid standard submissions.

    
12.08.2016 / 16:25