Load a file from an angular scope function js

0

I have a type submit button, which uploads the file to its respective httppostfileBase, however I would like to load it without the need to give that button submit if not in another.

    
asked by Eduardo Chávez 19.09.2017 в 01:44
source

1 answer

0

It is possible to click a button no matter where it is located and submit it, you only have to link your form to a function through the event ng-submit and the same function link it to an event ng-click :

<div ng-app>
    <div ng-controller="Ctrl">
        <form ng-submit="submit()" id="myForm">
            ...
            <input type="submit" id="submit" value="Submit" />
        </form>
        <button ng-click="submit()">Submit 2</button>
    </div>
 <button ng-click="submit()">Submit 3</button>
</div>

But from there you stop using Angular and within the Angular controller you use Javascript vanilla as the following:

function Ctrl($scope) {
    document.getElementById("myForm").submit();
}

The other option to continue using Angular is to send the file through AJAX.

    
answered by 19.09.2017 в 02:05