Multiple directives [myPopup, myDraggable] asking for new/isolated scope

后端 未结 7 708
情书的邮戳
情书的邮戳 2020-12-02 18:21

I wrote a directive for dialogs (myPopup) and another one for dragging this dialog (myDraggable), but I allways get the error:

Multiple directives [m

7条回答
  •  隐瞒了意图╮
    2020-12-02 18:57

    From docs:

    Example scenarios of multiple incompatible directives applied to the same element include:

    Multiple directives requesting isolated scope.

    Multiple directives publishing a controller under the same name.

    Multiple directives declared with the transclusion option.

    Multiple directives attempting to define a template or templateURL.

    Try removing isolate scope on myDraggable's directive:

    app.directive('myDraggable', ['$document',
        function ($document) {
        return {
            restrict: 'A',
            replace: false,
            scope: { enabled: '=myDraggable' }, //remove this line
    

    Replace scope.enabled with attrs.enabled:

    if (attrs.enabled == "true") {
    

    And modify your template to bind the enable attribute:

    DEMO

提交回复
热议问题