sani sani - 4 months ago 89
AngularJS Question

Error: [$compile:multidir] Multiple directives

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

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.

Comments