-2
我使用ckeditor的表單工作正常,但我希望當按大型模型按鈕時,然後bootstrap模式應該打開這個ckeditor和模式當你按下保存按鈕然後文本應該顯示在div標籤你在ckeditor中輸入的內容。ckEditor in bootstrap modal angularjs
我的HTML代碼
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>ckEditor demo</title>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.11.0.js"></script>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js'></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular-sanitize.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular-resource.js"></script>
<!--<link rel="stylesheet" type="text/css" href="/css/result-light.css">-->
<script type='text/javascript' src="http://ckeditor.com/apps/ckeditor/4.2.1/ckeditor.js"></script>
<script type='text/javascript' src="script.js"></script>
<style type='text/css'></style>
</head>
<body ng-app="myApp">
<div ng-controller="myCtrl">
<script type="text/ng-template" id="myModalContent">
<div class="modal-header">
<h3 class="modal-title">I'm a modal!</h3>
</div>
<div class="modal-body">
<textarea class="ck-editor" ng-model="text"></textarea>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="ok()">OK</button>
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
</div>
</script>
<button class="btn btn-default" ng-click="open('lg')" >Large modal</button>
<h3>Result HTML:</h3>
<div ng-bind-html-unsafe="text"></div>
</div>
</body>
</html>
我的腳本代碼
var myApp = angular.module('myApp', []);
var myCtrl = function ($scope) {
$scope.text = 'this is test';
};
myApp.directive('ckEditor', [function() {
return {
require: '?ngModel',
restrict: 'C',
link: function (scope, elm, attr, model) {
var isReady = false;
var data = [];
var ck = CKEDITOR.replace(elm[0]);
function setData() {
if (!data.length) {
return;
}
var d = data.splice(0, 1);
ck.setData(d[0] || '<span></span>', function() {
setData();
isReady = true;
});
}
ck.on('instanceReady', function (e) {
if (model) {
setData();
}
});
elm.bind('$destroy', function() {
ck.destroy(false);
});
if (model) {
ck.on('change', function() {
scope.$apply(function() {
var data = ck.getData();
if (data == '<span></span>') {
data = null;
}
model.$setViewValue(data);
});
});
model.$render = function (value) {
if (model.$viewValue === undefined) {
model.$setViewValue(null);
model.$viewValue = null;
}
data.push(model.$viewValue);
if (isReady) {
isReady = false;
setData();
}
};
}
}
};
}]);
您應該將代碼隔離在特定的問題,而不是粘貼您的整個腳本 – 2014-09-25 15:42:57
ok了。我還保留了一個鏈接... – 2014-09-25 15:56:19