Created
September 9, 2015 15:57
-
-
Save matthewbednarski/a2a0acf4427f9d017a90 to your computer and use it in GitHub Desktop.
a directive to show a single available item as a text box
This file contains hidden or 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
| (function() { | |
| var app = angular.module('mcbSingleSelect', []) | |
| .directive('singleSelect', [singleSelectDirective]); | |
| function singleSelectDirective() { | |
| return { | |
| restrict: 'EA', //E = element, A = attribute, C = class, M = comment | |
| scope: { | |
| //@ reads the attribute value, = provides two-way binding, & works with functions | |
| optionsList: '=?', | |
| name: '@', | |
| model: '=?', | |
| displayKey : '@' | |
| }, | |
| templateUrl: 'directive/single-select-directive.html' | |
| // template: function(ele, atts) { | |
| // console.dir(atts.displayKey); | |
| // return '<div> ' + | |
| // '<div ng-show="optionsList !== undefined && optionsList.length > 1"> ' + | |
| // ' <select class="form-control" name="{{name}}1 ' + | |
| // ' ng-options="item.' + atts.displayKey + ' for item in optionsList" ng-model="model" ' + | |
| // ' required> ' + | |
| // ' </select> ' + | |
| // '</div> ' + | |
| // '<div ng-show="optionsList === undefined || ( optionsList.length < 2)"> ' + | |
| // '<input class="form-control" name="{{name}}" ' + | |
| // 'ng-model="model.' + atts.displayKey + '" ' + | |
| // 'readonly> ' + | |
| // '</input> ' + | |
| // '</div> ' + | |
| // '</div> '; | |
| // } | |
| }; | |
| } | |
| })(); | |
| /** | |
| <div> | |
| <div ng-show="optionsList !== undefined && optionsList.length > 1"> | |
| <select class="form-control" name="{{name}}1 " | |
| ng-options="item.{{display}} for item in optionsList" ng-model="model" | |
| required> | |
| </select> | |
| </div> | |
| <div ng-show="optionsList === undefined || ( optionsList.length < 2)"> | |
| <input class="form-control" name="{{name}}" | |
| ng-model="model.display" | |
| readonly> | |
| </input> | |
| </div> | |
| </div> | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment