我有这样的自定义指令:
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); } } }; });
将lang =’fa’属性添加到所有输入:文本,我也使用DatePicker angular Ui,但我收到一个错误:
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">
当我在我的表单中评论datePicker一切正常.
任何的想法?谢谢
解决方法
该指令实际上并不需要新的子范围(既不是孤立的).使用scope配置它会好得多:false.它不仅可以纠正这个问题,还可以保存几个(当然是视图的设计)不必要的范围对象创建.