GitHub_angular.js: 583
Illustration of comment to https://github.com/angular/angular.js/issues/583.
by Renaud LITTOLFF
HTML
<script src="http://code.angularjs.org/1.3.0-rc.3/angular.min.js"></script>
<div ng-controller="mainCtrl">
<form name="myForm">
<p>Input 1: <input type="email" name="myInput1" ng-model="value1" required /></p>
<div ng-if="myForm.myInput1.$touched && myForm.myInput1.$dirty" style="color: red;">
<p ng-if="myForm.myInput1.$error.required">Required !</p>
<p ng-if="myForm.myInput1.$error.email">Invalid email !</p>
</div>
</form>
<hr />
<pre>myInput1.$touched: {{myForm.myInput1.$touched}}</pre>
<pre>myInput1.$dirty: {{myForm.myInput1.$dirty}}</pre>
</div>
<!-- -=-=-=-=- -=[IGNORE BELOW THIS LINE]=- -=-=-=-=- -->
<!-- Page Footer -->
<small class="footer" ng-controller="footerCtrl">
<b>Angular v{{version.full}}</b> ({{version.codeName}})
<span class="right">
©
<a ng-href="{{author.url}}" target="_blank">{{author.name}}</a>
</span>
</small>
CSS
/* -=-=-=-=- -=[IGNORE BELOW THIS LINE]=- -=-=-=-=- */
/* Page Footer */
body { padding-bottom: 22px; }
.footer { background-color: White; border-top: 1px solid rgba(100, 100, 100, 0.33); bottom: 0; display: block; font-size: 0.75em; height: 20px; left: 0; margin: 0 5px; overflow: auto; padding: 5px; position: fixed; right: 0; }
.right { float: right; }
JavaScript
var app = angular.module('myApp', []);
app.controller('mainCtrl', function ($scope) {});
app.directive('input', function () {
return {
restrict: 'E',
require: '?ngModel',
link: function (scope, elem, attrs, ctrl) {
if (!ctrl) return;
elem.on('blur', function (evt) {
scope.$apply(function () {
if (ctrl.$pristine) ctrl.$setUntouched();
});
});
}
};
});
/* -=-=-=-=- -=[IGNORE BELOW THIS LINE]=- -=-=-=-=- */
/* Page Footer */
app.controller('footerCtrl', function ($scope) {
$scope.version = angular.version;
$scope.author = {
name: 'GKalpak',
url: '//github.com/gkalpak'
};
});