How To Validate Input Without Form Tag In Angular Js?
In popup I am showing html which I copy from another div and show in popup. Here I want to validate this input field for required. and show error message below input box. index.h
Solution 1:
See updated plunker.
We can use $compile directive.
$scope.changeZipCode = function()
{
$rootScope.myModal = true;
var firstDivContent = document.getElementById('updateZipContent');
var secondDivContent = document.getElementById('dynamicContect');
var clonedElement = $compile(firstDivContent.innerHTML)($scope, function(clonedElement, scope) {
//attach the clone to DOM document at the right place
secondDivContent.innerHTML ="";
angular.element(secondDivContent).append(clonedElement);
});
}
Solution 2:
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
});
<htmlng-app="plunker"><head><metacharset="utf-8" /><title>AngularJS Plunker</title><script>document.write('<base href="' + document.location + '" />');</script><linkrel="stylesheet"href="style.css" /><scriptdata-require="angular.js@1.2.x"src="https://code.angularjs.org/1.2.25/angular.js"data-semver="1.2.25"></script></head><bodyng-controller="MainCtrl"><divng-form="myForm"><inputtype="text"requiredng-model="user.name"placeholder="Username"><buttonng-click="doSomething()"ng-disabled="myForm.$invalid">DO</button></div></body></html>
Post a Comment for "How To Validate Input Without Form Tag In Angular Js?"