Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.directive('dropdown', function ($timeout) {
- return {
- restrict: 'E',
- template: '<div class="btn-group" dropdown>' +
- '<button id="dropdownDirective" class="btn dropdown-toggle" dropdown-toggle>' +
- '{{ items[ngModel].name }}' +
- '<span class="caret"></span>' +
- '</button>' +
- '<ul class="dropdown-menu" role ="menu" aria-label="dLabel">' +
- '<li ng-repeat="item in items">'+
- '<a href="#" ng-bind="item.name" ng-click = "select(item)" >< / a >' +
- '</li>'+
- '</ul>'+
- '</div>',
- scope: {
- ngModel: '=', // selected option
- items: '=', // options
- },
- link: function (scope, element, attrs) {
- scope.select = function (item) {
- scope.ngModel = item.id;
- };
- }
- };
- });
- <dropdown id="modalSelect"
- ng-model="ahs.modal.modalId"
- items="es.modal.data">
- </dropdown>
- app.directive('dropdown', function ($timeout) {
- return {
- require: "ngModel",
- restrict: 'E',
- template: [...]
- scope: {
- items: '=', // options
- },
- link: function (scope, element, attrs, ngModelController) {
- ngModelController.$setViewValue(...);
- ngModelController.$setPristine(...);
- etc.
- }
- };
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement