Skip to content

Instantly share code, notes, and snippets.

@wcc526
Last active August 29, 2015 14:17
Show Gist options
  • Save wcc526/6acfae75337be8b2111b to your computer and use it in GitHub Desktop.
Save wcc526/6acfae75337be8b2111b to your computer and use it in GitHub Desktop.
angular form controller
(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');
}
};
}]);
})();
<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