Created
December 11, 2012 02:55
-
-
Save presstube/4255541 to your computer and use it in GitHub Desktop.
angularjs directive optional attributes
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
angular.module('formComponents', []) | |
.directive('formInput', function() { | |
return { | |
restrict: 'E', | |
compile: function(element, attrs) | |
{ | |
var type = attrs.type || 'text'; | |
var required = attrs.hasOwnProperty('required') ? "required='required'" : ""; | |
var htmlText = '<div class="control-group">' + | |
'<label class="control-label" for="' + attrs.formId + '">' + attrs.label + '</label>' + | |
'<div class="controls">' + | |
'<input type="' + type + '" class="input-xlarge" id="' + attrs.formId + '" name="' + attrs.formId + '" ' + required + '>' + | |
'</div>' + | |
'</div>'; | |
element.replaceWith(htmlText); | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment