在AngularJS控制器中获取TinyMCE文本内容
我正在请求angularJS,我想要的是提交一个带有tinymce ui文本区域的表单,并提交HTML内容和文本内容 现在我的tinyMce文本区正在工作 我得到我想要的。 我只是不知道如何在我的控制器中检索它 如果不使用消毒功能,我怎么做?在AngularJS控制器中获取TinyMCE文本内容,angularjs,tinymce,angular-ui,Angularjs,Tinymce,Angular Ui,我正在请求angularJS,我想要的是提交一个带有tinymce ui文本区域的表单,并提交HTML内容和文本内容 现在我的tinyMce文本区正在工作 我得到我想要的。 我只是不知道如何在我的控制器中检索它 如果不使用消毒功能,我怎么做? 谢谢。您可以使用init_instance_回调在活动tinymce编辑器中为KeyUp、ExecCommand和SetContent附加事件侦听器,并在触发这些事件时绑定$scope变量。如果您检查ui tinymce指令源代码,您将看到这些事件用于更新
谢谢。您可以使用
init_instance_回调
在活动tinymce编辑器
中为KeyUp
、ExecCommand
和SetContent
附加事件侦听器,并在触发这些事件时绑定$scope
变量。如果您检查ui tinymce
指令源代码,您将看到这些事件用于更新模型
JAVASCRIPT
$scope.tinymceOptions = {
resize: false,
width: 400, // I *think* its a number and not '400' string
height: 300,
plugins: 'textcolor link',
toolbar: "undo redo styleselect bold italic forecolor backcolor",
menu : { // this is the complete default configuration
edit : {title : 'Edit' , items : 'undo redo | cut copy paste pastetext | selectall'},
insert : {title : 'Insert', items : 'link media | template hr'},
format : {title : 'Format', items : 'bold italic underline strikethrough superscript subscript | formats | removeformat'},
},
init_instance_callback: function(editor) {
var textContentTrigger = function() {
$scope.textContent = editor.getBody().textContent;
$scope.$apply();
};
editor.on('KeyUp', textContentTrigger);
editor.on('ExecCommand', textContentTrigger);
editor.on('SetContent', function(e) {
if(!e.initial)
textContentTrigger();
});
}
};
HTML
<textarea>{{textContent}}</textarea>
{{textContent}
它通过您设置的ng型号
绑定到$scope.user.commentaireValue
。谢谢!它就像一个符咒:)以防万一,它可以帮助我正在寻找editor.getContent({format:'text'})的人;以便使用原始文本检索换行符。
app.controller('UserCreationCtrl', ['$scope', 'UsersFactory', '$location',
function ($scope, UsersFactory, $location) {
// callback for ng-click 'createNewUser':
$scope.createNewUser = function () {
UsersFactory.create($scope.user);
$location.path('/user-list');
};
$scope.options=[
{name:'black', shade:'dark'},
{name:'white', shade:'light'},
{name:'red', shade:'dark'},
{name:'blue', shade:'dark'},
{name:'yellow', shade:'light'}
];
$scope.correctlySelected = $scope.options[1];
$scope.tinymceOptions = {
resize: false,
width: 400, // I *think* its a number and not '400' string
height: 300,
plugins: 'textcolor link',
toolbar: "undo redo styleselect bold italic forecolor backcolor",
menu : { // this is the complete default configuration
edit : {title : 'Edit' , items : 'undo redo | cut copy paste pastetext | selectall'},
insert : {title : 'Insert', items : 'link media | template hr'},
format : {title : 'Format', items : 'bold italic underline strikethrough superscript subscript | formats | removeformat'},
}
};
//tinyMCE.get('tinymce1').getBody().textContent;
}]);
$scope.tinymceOptions = {
resize: false,
width: 400, // I *think* its a number and not '400' string
height: 300,
plugins: 'textcolor link',
toolbar: "undo redo styleselect bold italic forecolor backcolor",
menu : { // this is the complete default configuration
edit : {title : 'Edit' , items : 'undo redo | cut copy paste pastetext | selectall'},
insert : {title : 'Insert', items : 'link media | template hr'},
format : {title : 'Format', items : 'bold italic underline strikethrough superscript subscript | formats | removeformat'},
},
init_instance_callback: function(editor) {
var textContentTrigger = function() {
$scope.textContent = editor.getBody().textContent;
$scope.$apply();
};
editor.on('KeyUp', textContentTrigger);
editor.on('ExecCommand', textContentTrigger);
editor.on('SetContent', function(e) {
if(!e.initial)
textContentTrigger();
});
}
};
<textarea>{{textContent}}</textarea>