I am learnig angular and I am trying to implement the following behavior using vanilla angular.
I have the following html page that creates dynamically text inputs and a button.
By pressing on the button I want to validate all the inputs (only to check if they are not empty) and show the message under the invalid input. It is very easy to implement with jQuery or even with plain JS, But I am struggling with angular.
jsFiddle - https://jsfiddle.net/AlexLavriv/zkdodm4b/1/
(function(angular) {
'use strict';
angular.module('scopeExample', [])
.controller('MyController', ['$scope', function($scope) {
$scope.instances = [1,2,3,4,5,6,7,8,9,10];
$scope.clicked = function()
{
alert("clicked");
};
}]);
})(window.angular);
<body ng-app="scopeExample">
<div ng-controller="MyController">
<div ng-repeat="instance in instances">
<form name="instance{{$index}}">
<input type="text" required="true" ng-model="txt" name="txt">
<div ng-show="instance{{$index}}.txt.$invalid && instance{{$index}}.txt.$touched"> the input is illegal</div>
</form>
</div>
<input type="button" value="Press" ng-click="clicked()">
</div>
</body>