I'm attempting to build a new directive on top of an already existing directive but I am halted in my proces. When loading the page I'm facing the following error:
Multiple directives [directive#1, directive#2] asking for isolated scope on
<easymodal title="Test-Title" text="Text-Text" oncancel="show = false" onok="alert();">
The base directive looks like this:
Rohan.directive('easymodal', function () { return { restrict: 'E', // priority: 200, transclude: true, replace: true, scope:{ showModal: "=show", callback: "=closeFunction", dismissable: '&' }, template: '<div data-ng-show="showModal" class="modal-container">' + '<div class="modal-body">' + '<div class="title"><span data-translate></span><a data-ng-show="dismissable" data-ng-click="dismiss()">x</a></div>' + '<div data-ng-transclude></div>' + '</div>' + '<div class="modal-backdrop" data-ng-click="dismiss()"></div>' + '</div>' }; });
And my wrapper directive looks like this:
Rohan.directive('easydialog', function () { return { restrict: 'E', transclude: true, scope: {title: '@', text: '@', onOk: '&', onCancel: '&'}, replace: true, template: '<easymodal>' + '{{text}} ' + '<hr>' + '<button ng-click="{{onCancel}}" value="Cancel"' + '<button ng-click="{{onOk}}" value="Ok"' + '</easymodal>' }; });
My html looks like this:
<easydialog title="Test-Title" text="Text-Text" onCancel="show = false" onOk="alert();" />
At first I though my title attribute was conflicting so I removed that attribute in the html line and from my wrapper directive but it was not effective.
The three types of directives in Angular are attribute directives, structural directives, and components.
You can not use two structural directives on the same element. You need to wrap your element in another one. It's advised to use ng-container since it wont be rendered in DOM.
There are four types of directives in Angular, Components directives. Structural directives. Attribute directives.
You need to change your easydialog
template and wrap <easymodal>
in a <div>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With