2017-07-12 71 views
0

指令無法通過配置ngModel

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-模型= 「ngModel」,而不是NG-模型= 「稱號」。我嘗試將模板ng-model =「ngModel」更改爲ng-model =「{{ngModel}}」。但它沒有奏效。不知道爲什麼。

回答

0

嘗試改變指令的範圍

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>` 
    } 
+0

沒有傷心地工作。輸出只是'ng-model =「bindModel」'而不是所需的'ng-model =「標題」' –