加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 错误:[$compile:multidir]多个指令

发布时间:2020-12-17 17:43:58 所属栏目:安全 来源:网络整理
导读:我有这样的自定义指令: 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
我有这样的自定义指令:

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.它不仅可以纠正这个问题,还可以保存几个(当然是视图的设计)不必要的范围对象创建.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读