UNPKG

landers.angular

Version:

landers.angular

27 lines (25 loc) 1.5 kB
;angular.module('Landers.angular') .directive('inputRadioOrText', ['$compile', function($compile){ return { restrict: 'A', link : function($scope, $ele, $attrs) { var tag = $ele.tag(); var ngModel = $attrs['ngModel']; var listModel = $attrs['listModel']; var html = ''; html += tag == 'input' ? '<input ng-if="%ngModel%" ng-model="%ngModel%" class="form-control" type="text"/>' : '<textarea ng-if="%ngModel%" ng-model="%ngModel%" class="form-control"></textarea>'; html += '<div class="zoc mb-5" ng-if="!%ngModel%">'; html += ' <label class="btn btn-default btn-sm btn-checker ph10 mr5 mb5" ng-repeat="item in %listModel%" ng-class="{\'active\': item == %ngModel%, \'btn-info\': item == %ngModel%}" title="{{item}}">'; html += ' <input type="radio" name="password" ng-model="%ngModel%" value="{{ item }}" class="hidden">'; html += ' <span>{{item}}</span>'; html += ' <span class="checker zoom08"><i class="icon glyphicon glyphicon-ok"></i></span>'; html += ' </label>'; html += '</div>'; html = html.replaceAll('%ngModel%', ngModel); html = html.replaceAll('%listModel%', listModel); $ele.replaceWith($compile(html)($scope)); } } }]);