GitHub_angular.js: 583
Illustration of comment to https://github.com/angular/angular.js/issues/583.
by ExpertSystem
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="text" name="myInput1" ng-model="value1" /></p>
<p>Input 2: <input type="text" name="myInput2" ng-model="value2" /></p>
</form>
<hr />
<pre>myInput1.$touched: {{myForm.myInput1.$touched}}</pre>
<pre>myInput1.$dirty: {{myForm.myInput1.$dirty}}</pre>
<pre>myInput2.$touched: {{myForm.myInput2.$touched}}</pre>
<pre>myInput2.$dirty: {{myForm.myInput2.$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'
};
});