Angularjs Examples

AJS Examples

AngularJS ng-Submit Directive

AngularJS ng-Submit prevents the default form submition action if the form does not contain action or data-action attributes. It enables you to bind angular expressions on onsubmit event.


<form ng-submit="yourFunction()">

AngularJS ng-Submit Directive Example

<title>My first AngularJS ng-submit Directive code</title>
 <!-- -->
<Script SRC="">  
function CustomController($scope) {
  $scope.items = [
    {text:'', done:true}];

  $scope.addList = function() {
    $scope.items.push({text:$scope.itemText, done:false});
    $scope.itemText = '';

  $scope.remaining = function() {
    var count = 0;
    angular.forEach($scope.items, function(todo) {
      count += todo.done ? 0 : 1;
    return count;

<div ng-app>
  <h2>ng-submit Example</h2>
  <div ng-controller="CustomController">
       <ul class="unstyled">
      <li ng-repeat="item in items">
        <p ng-model="item.done"/>
        <span class="done-{{item.done}}">{{item.text}}</span>
    <form ng-submit="addList()">
      <input type="text" ng-model="itemText"  size="30"
             placeholder="add new item here">
      <input class="btn-primary" type="submit" value="add">
See Live Example