71 lines
3.6 KiB
HTML
Executable file
71 lines
3.6 KiB
HTML
Executable file
<a href="http://github.com/angular/angular.js/tree/v1.2.0rc1/src/ng/directive/ngEventDirs.js#L215" class="view-source btn btn-action"><i class="icon-zoom-in"> </i> View source</a><a href="http://github.com/angular/angular.js/edit/master/src/ng/directive/ngEventDirs.js" class="improve-docs btn btn-primary"><i class="icon-edit"> </i> Improve this doc</a><h1><code ng:non-bindable="">ngSubmit</code>
|
|
<div><span class="hint">directive in module <code ng:non-bindable="">ng</code>
|
|
</span>
|
|
</div>
|
|
</h1>
|
|
<div><h2 id="Description">Description</h2>
|
|
<div class="description"><div class="ng-directive-page ng-directive-ngsubmit-page"><p>Enables binding angular expressions to onsubmit events.</p>
|
|
<p>Additionally it prevents the default action (which for form means sending the request to the
|
|
server and reloading the current page) <strong>but only if the form does not contain an <code>action</code>
|
|
attribute</strong>.</p>
|
|
</div></div>
|
|
<h2 id="Usage">Usage</h2>
|
|
<div class="usage">as attribute<pre class="prettyprint linenums"><form ng-submit="{expression}">
|
|
...
|
|
</form></pre>
|
|
as class<pre class="prettyprint linenums"><form class="ng-submit: {expression};">
|
|
...
|
|
</form></pre>
|
|
<h4 id="parameters">Parameters</h4><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>ngSubmit</td><td><a href="" class="label type-hint type-hint-expression">expression</a></td><td><div class="ng-directive-page ng-directive-ngsubmit-page"><p><a href="guide/expression">Expression</a> to eval. (Event object is available as <code>$event</code>)</p>
|
|
</div></td></tr></tbody></table></div>
|
|
<h2 id="Example">Example</h2>
|
|
<div class="example"><div class="ng-directive-page ng-directive-ngsubmit-page"><h4>Source</h2>
|
|
<div source-edit="" source-edit-deps="angular.js script.js" source-edit-html="index.html-75" source-edit-css="" source-edit-js="script.js-74" source-edit-json="" source-edit-unit="" source-edit-scenario="scenario.js-76"></div>
|
|
<div class="tabbable"><div class="tab-pane" title="index.html">
|
|
<pre class="prettyprint linenums" ng-set-text="index.html-75" ng-html-wrap=" angular.js script.js"></pre>
|
|
<script type="text/ng-template" id="index.html-75">
|
|
|
|
<form ng-submit="submit()" ng-controller="Ctrl">
|
|
Enter text and hit enter:
|
|
<input type="text" ng-model="text" name="text" />
|
|
<input type="submit" id="submit" value="Submit" />
|
|
<pre>list={{list}}</pre>
|
|
</form>
|
|
</script>
|
|
</div>
|
|
<div class="tab-pane" title="script.js">
|
|
<pre class="prettyprint linenums" ng-set-text="script.js-74"></pre>
|
|
<script type="text/ng-template" id="script.js-74">
|
|
function Ctrl($scope) {
|
|
$scope.list = [];
|
|
$scope.text = 'hello';
|
|
$scope.submit = function() {
|
|
if (this.text) {
|
|
this.list.push(this.text);
|
|
this.text = '';
|
|
}
|
|
};
|
|
}
|
|
</script>
|
|
</div>
|
|
<div class="tab-pane" title="End to end test">
|
|
<pre class="prettyprint linenums" ng-set-text="scenario.js-76"></pre>
|
|
<script type="text/ng-template" id="scenario.js-76">
|
|
it('should check ng-submit', function() {
|
|
expect(binding('list')).toBe('[]');
|
|
element('.doc-example-live #submit').click();
|
|
expect(binding('list')).toBe('["hello"]');
|
|
expect(input('text').val()).toBe('');
|
|
});
|
|
it('should ignore empty strings', function() {
|
|
expect(binding('list')).toBe('[]');
|
|
element('.doc-example-live #submit').click();
|
|
element('.doc-example-live #submit').click();
|
|
expect(binding('list')).toBe('["hello"]');
|
|
});
|
|
</script>
|
|
</div>
|
|
</div><h2>Demo</h4>
|
|
<div class="well doc-example-live animate-container" ng-embed-app="" ng-set-html="index.html-75" ng-eval-javascript="script.js-74"></div>
|
|
</div></div>
|
|
</div>
|