Last active
August 29, 2015 14:17
-
-
Save wcc526/6acfae75337be8b2111b to your computer and use it in GitHub Desktop.
angular form controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
'use strict'; | |
angular.module('App') | |
.controller('AboutFormCtrl',['$scope','$log',function($scope,$log){ | |
$log.debug('AboutFormCtrl'); | |
$scope.age = null; | |
$scope.generateAges = function(){ | |
var ages = []; | |
for(var i=18;i<=60; ++i){ | |
ages.push(i); | |
} | |
return ages; | |
}; | |
$scope.submit = function(){ | |
if($scope.aboutForm.$valid){ | |
alert("valid"); | |
} | |
else{ | |
alert('invalid'); | |
} | |
}; | |
}]); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<section> | |
<h2>ngSubmit</h2> | |
<form name="aboutForm" ng-submit="submit()" ng-controller="AboutFormCtrl"> | |
<div class="form-group"> | |
<label>Name:</label> | |
<input type="text" ng-model="name"/> | |
</div> | |
<div class="form-group"> | |
<label>Age:</label> | |
<select ng-model="age" ng-options="age for age in generateAges()"> | |
</select> | |
</div> | |
<input type="submit"/> | |
</form> | |
</section> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment