Created
August 26, 2014 19:11
-
-
Save mbalex99/19acc7cc359be93c00d6 to your computer and use it in GitHub Desktop.
ExpressJs Validation AngularJS Directive Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by maximilianalexander on 8/15/14. | |
*/ | |
angular.module('app').directive('validationMessage', function(){ | |
return { | |
restrict: 'E', | |
templateUrl: 'client/partials/validation-message.html', | |
scope: { | |
errorModels: "=", | |
errorKey: "@" | |
}, | |
link: function(scope, element, attrs){ | |
scope.$watchGroup(['errorModels', 'errorKey'], function(newValues, oldValues, scope){ | |
var models = newValues[0]; | |
var key = newValues[1]; | |
if(!models || !key){ | |
return; | |
} | |
var specificModel = models[key]; | |
var formGroup = element.closest('.form-group'); | |
if(specificModel){ | |
scope.message = specificModel.msg; | |
formGroup.addClass('has-error'); | |
}else{ | |
formGroup.removeClass('has-error'); | |
} | |
}); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<span class="help-block" ng-show="message"><i class="fa fa-times"></i> {{message}}</span> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment