【发布时间】:2015-03-23 07:52:45
【问题描述】:
我有一个这样的自定义指令:
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。 -
老师您好 :),您昨天拯救了我的一天,当我删除它时,自定义指令不起作用,因为在我的控制器中我添加了这个:$scope.lang = 'faLang';
-
:) 如果禁用
input指令(完全注释掉代码),问题是否仍然存在? -
没有一切都好,当我将范围设置为 false 时,我的输入之一得到 lang='fa'
-
嘿伙计,请把你的评论放在答案部分,那是我的错误,scope=false 成功了,谢谢
标签: angularjs angular-directive