Skip to content

Instantly share code, notes, and snippets.

View chandermani's full-sized avatar

Chandermani chandermani

  • London
View GitHub Profile
<input type="email"
ng-model='userEmail'
name='email' required
class="form-control"
custom-validator="disposable"
validate-functions='disposableMail'/>
$scope.duplicateMailRemoteCheck = function (email) {
return $timeout(function () {
return ['mail1@abc.com', 'mail2@abc.com', 'mail3@abc.com'].indexOf(email) >= 0 ? false : true;
}, 2000);
}
$scope.disposableMail = function (email) {
if (!email) return true;
return email.indexOf('@mailinator.com') >= 0 ? false : true;
}
<div>
<small class="error" ng-repeat="message in errorMessages" ng-show= "!modelController.$pristine && $first" class="warning">
{{message}}
</small>
</div>
<div data-validation-messages='' model-controller='form.email'
required-error="Email id is required."
email-error="Email is not in correct format." />
</div>
<input type="email" ng-model="user.email" name="uEmail" required /><br/>
<div ng-show="form.uEmail.$dirty && form.uEmail.$invalid">
<span ng-show="form.uEmail.$error.required">Tell us your email.</span>
<span ng-show="form.uEmail.$error.email">This is not a valid email.</span>
</div>
@chandermani
chandermani / validationdirectives.js
Last active August 29, 2015 13:57
AngularJS validation directives
angular.module('validation',[])
.directive('customValidator', [function () {
return {
restrict: 'A',
require: 'ngModel',
scope: { validateFunction: '&' },
link: function (scope, elm, attr, ngModelCtrl) {
ngModelCtrl.$parsers.push(function (value) {
var result = scope.validateFunction({ 'value': value });
if (result || result === false) {
app.factory(‘Items’,function($http) {
var items = [];
return {
list: function() {
var defer=$q.defer();
if (items.length == 0) { // items array is empty so populate it and return list from server to controller
$http.get(‘/?items’).then(function(response) {
items = response.data.items;
defer.resolve(items);
});
angular.module('module1',[]); //declares a module. Note the second parameter which takes dependencies
angular.module('module1'); //gets a module with name module1, no second parameter
var element = document.getElementsById('id');
var scope = angular.element(element).scope();