【问题标题】:Unable to pass configuration to ngModel无法将配置传递给 ngModel
【发布时间】:2017-07-13 05:16:04
【问题描述】:

指令

return {
     restrict: 'E',
     replace: true,
     transclude: true,
     require: ['^?angular-redactor', '^?ngModel'],
     scope: {
       options: '='
     },
      template: `<div ng-if="options.type=='redactor'">
             <textarea 
               id="{{options.id}}"
               ng-model="ngModel"
               ng-disabled="!hasPermission('editPageTitle')"
               height="{{options.height}}"
               style="{{options.style}}"
               redactor="{{options.config}}"> 
            </textarea>
          </div>`
        }

HTML

<txt ng-model="title"
    options="{
        type: 'redactor',
        id: 'title-input',
        height: '26px',
        style: 'resize:none; max-height: 32px' ,
        config: {
            minHeight: 37
        }
    }">
</txt>

我得到的结果是 ng-model="ngModel" 而不是 ng-model="title"。我尝试将模板 ng-model="ngModel" 更改为 ng-model="{{ngModel}}"。但它没有用。不知道为什么。

【问题讨论】:

    标签: html angularjs angularjs-directive


    【解决方案1】:

    尝试将指令的范围更改为

    scope: {
       options: '=',
       bindModel:'=ngModel'
    },
    

    模板应该是

        template: `<div ng-if="options.type=='redactor'">
             <textarea 
               id="{{options.id}}"
               ng-model="bindModel"
               ng-disabled="!hasPermission('editPageTitle')"
               height="{{options.height}}"
               style="{{options.style}}"
               redactor="{{options.config}}"> 
            </textarea>
          </div>`
        }
    

    【讨论】:

    • 很遗憾没有工作。输出只是 ng-model="bindModel" 而不是所需的 ng-model="title"
    猜你喜欢
    • 1970-01-01
    • 2017-05-12
    • 1970-01-01
    • 2011-12-06
    • 1970-01-01
    • 1970-01-01
    • 2017-11-23
    • 2014-05-07
    • 1970-01-01
    相关资源
    最近更新 更多