Advertisement
Guest User

Untitled

a guest
Mar 1st, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. app.directive('dropdown', function ($timeout) {
  2. return {
  3. restrict: 'E',
  4. template: '<div class="btn-group" dropdown>' +
  5. '<button id="dropdownDirective" class="btn dropdown-toggle" dropdown-toggle>' +
  6. '{{ items[ngModel].name }}' +
  7. '<span class="caret"></span>' +
  8. '</button>' +
  9. '<ul class="dropdown-menu" role ="menu" aria-label="dLabel">' +
  10. '<li ng-repeat="item in items">'+
  11. '<a href="#" ng-bind="item.name" ng-click = "select(item)" >< / a >' +
  12. '</li>'+
  13. '</ul>'+
  14. '</div>',
  15. scope: {
  16. ngModel: '=', // selected option
  17. items: '=', // options
  18. },
  19. link: function (scope, element, attrs) {
  20. scope.select = function (item) {
  21. scope.ngModel = item.id;
  22. };
  23. }
  24. };
  25. });
  26.  
  27. <dropdown id="modalSelect"
  28. ng-model="ahs.modal.modalId"
  29. items="es.modal.data">
  30. </dropdown>
  31.  
  32. app.directive('dropdown', function ($timeout) {
  33. return {
  34. require: "ngModel",
  35. restrict: 'E',
  36. template: [...]
  37. scope: {
  38. items: '=', // options
  39. },
  40. link: function (scope, element, attrs, ngModelController) {
  41. ngModelController.$setViewValue(...);
  42. ngModelController.$setPristine(...);
  43. etc.
  44. }
  45. };
  46. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement