Form input ng-blur
by Rob Rothe
HTML
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<div ng-app="app" class="container">
<div ng-controller="Controller1 as ctrl">
<form name="myform">
<div ng-repeat="(key, keyvalue) in ctrl.formfields">
<input name="{{key}}" ng-model="ctrl.formfields[key]" ng-blur="ctrl.watchFormField(key)">
</div>
</form>
</div>
</div>
CSS
body {
padding-top: 20px;
}
JavaScript
angular
.module('app', [])
.controller('Controller1', Controller1);
function Controller1($scope) {
var vm = this;
vm.formfields = {"FIELD1":"", "FIELD2":"", "FIELD3":"Prepopulated", "FIELD4":""};
vm.watchFormField = function(fieldKey) {
alert(fieldKey + 'changed to ' + vm.formfields[fieldKey]);
}
}