2014-11-19 6 views
0

У меня будет приложение с функцией перетаскивания. Кроме того, в нем можно будет сбросить ckeditor.AngularJS ckEditor, несколько экземпляров

Как можно создать новый экземпляр ckeditor, проблема у меня есть, все экземпляры будут иметь одну и ту же «ng-model».

Я видел ответ с «нг-повтором» здесь: jsfiddle.net/TheSharpieOne/cPTr7/ , но мое приложение не имеет такой ретранслятор.

Спасибо

ответ

0

были подобные проблемы, не знаю, если это может помочь вам, но решить мою проблему.

var app = angular.module('app', []); 
 

 
app.directive('ckEditor', [function() { 
 
    return { 
 
     require: '?ngModel', 
 
     link: function ($scope, elm, attr, ngModel) { 
 

 
      var ck = CKEDITOR.replace(elm[0]); 
 

 
      ck.on('pasteState', function() { 
 
       $scope.$apply(function() { 
 
        ngModel.$setViewValue(ck.getData()); 
 
       }); 
 
      }); 
 

 
      ngModel.$render = function (value) { 
 
       ck.setData(ngModel.$modelValue); 
 
      }; 
 
     } 
 
    }; 
 
}]) 
 

 
function myCtrl($scope){ 
 
    $scope.ckEditors = []; 
 
    $scope.post = 0; 
 
    $scope.addEditor = function(id){ 
 
     $scope.ckEditors.pop(); 
 
     $scope.post=id; 
 
     var rand = ""+(Math.random() * 10000); 
 
     $scope.ckEditors.push({value:rand}); 
 
    } 
 
}
<script src="http://ckeditor.com/apps/ckeditor/4.2/ckeditor.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div data-ng-app="app" data-ng-controller="myCtrl"> 
 
    
 
<h3>Post1:</h3> 
 
    <div ng-repeat="editor in ckEditors"> 
 
    <textarea ng-if="post==1" data-ng-model="editor.value" data-ck-editor></textarea> 
 
    <br /> 
 
    </div> 
 
    <button ng-click="addEditor(1)">New Editor</button> 
 

 
<h3>Post2:</h3> 
 
    <div ng-repeat="editor in ckEditors" > 
 
    <textarea ng-if="post==2" data-ng-model="editor.value" data-ck-editor></textarea> 
 
    <br /> 
 
    </div> 
 
    <button ng-click="addEditor(2)">New Editor</button>

http://jsfiddle.net/PauloSegundo/mrLz8eba/

Смежные вопросы