2015-11-08 127 views
0

我使用下面的代碼使用angularjs指令顯示ckeditor。但它不會顯示在頁面中。Ckeditor角度指令不起作用

指令:

'use strict'; 
define('ngCkeditor', ['app'], function (app) { 
app.directive('ngCkeditor', function() { 
    return { 
     restrict: 'AC', 
     require: 'ngModel', 
     link: function (scope, element, attr, ngModel) { 

      debugger; 
      var ck = CKEDITOR.replace(element[0]); 
      if (!ngModel) return; 
      ck.on('pasteState', function() { 
       scope.$apply(function() { 
        ngModel.$setViewValue(ck.getData()); 
       }); 
      }); 
      ngModel.$render = function (value) { 
       ck.setData(ngModel.$viewValue); 
      }; 

     } 
    }; 
}); 
}); 

和控制器:

define('ckEditorController', ['app', 'ckeditor', 'ckfinder', 'ngCkeditor'], function (app, ckeditor, ckfinder, ngCkeditor) { 
app.lazy.controller('ckEditorController', ['$scope', '$location', function ($scope, $location) { 

    debugger; 
     $scope.text = 'this is test'; 

}]); 
}); 

,這是HTML:

<link href="~/app/lib/editor/css/bootstrap.css" rel="stylesheet" /> 
<link href="~/app/lib/editor/ng-ckeditor.css" rel="stylesheet" /> 
<h2>CkEditor</h2> 
<form name="frm"> 
<div ng-controller="ckEditorController"> 
    <textarea class="ng-Ckeditor" ng-model="text"></textarea> 
    <textarea ng-ckeditor ng-model="text"></textarea> 
    <h3>Result HTML:</h3> 
    <div ng-bind-html-unsafe="text"></div> 
</div> 

在我看來,在指令中的鏈接部分不冷杉e。

感謝

更新:

看看jsfiddle鏈接。它像一個魅力。但我的不

回答

0

您應該使用正確的指令名:

<textarea ng-ckeditor ng-model="text"></textarea> 

注意'ngCkeditor'指令名稱對應於「NG-CKEditor的」歸一化的形式,由於駝峯蛇,大小寫轉換。

檢查這個答案,我提供了詳細的解釋。 https://stackoverflow.com/a/33460305/949476

+0

你能否提供給我更多的細節! –

+0

不,它不適用於「ng-ck-editor」 –

+0

如果您命名ngCkeditor指令,它應該是ng-ckeditor。 – dfsq