Error: [$compile:multidir] Multiple directives

Sadeghbayan picture Sadeghbayan · Jan 24, 2015 · Viewed 15.3k times · Source

I have a custom directive like this :

myApp.directive('input', function () {
    return {
        restrict: 'E',
        scope: true,
        link: function (scope, elem) {
            if (scope.lang && elem.attr('type') === 'text') {
                elem.attr('lang', 'fa');
                console.log(scope.lang);
            }
        }
    };
});  

that add lang='fa' attribute to all input:text and also i'm using DatePicker angular Ui but i get an error :

    Error:   
    [$compile:multidir] Multiple directives [datepickerPopupPersian, input] asking for  
      
     new/isolated scope on:  
     <input type="date" name="birth" class="form-control ng-pristine   
    ng-untouched ng-valid"  
     datepicker-popup-persian="{{formats.ShowDate}}" tabindex="7"   
    ng-model="requesterViewModel.BirthDate"   
    is-open="datePicker.opened" datepicker-options="dateOptions" date-disabled="disabled(date, mode)"  
 close-text="بسته"  
     max-date="dt">

when i comment datePicker in my form everything work well .
Any idea? Thanks

Answer

Nikos Paraskevopoulos picture Nikos Paraskevopoulos · Jan 24, 2015

This directive does not really need a new child scope (neither an isolated). It is much better to configure it with scope: false. It will not only correct this problem, but also save several (depending on the design of the views of course) unnecessary scope object creations.