ckeditor和angularjs之间的绑定数据

时间:2017-12-24 21:26:18

标签: javascript angularjs ckeditor

大家好我想把ckeditor中的文本传递给我的代码angularjs但总是未定义 这是html

 <textarea name="editor1" ng-model="editor1"  id="editor1" rows="10" cols="80">

<button type="submit" class="button expand success" ng-click="insertArticle()">Save</button>

这是angularjs

  $scope.insertArticle = function(){
            $scope.dataInsert = {
              'editor1':$scope.editor1
            };
$http.post('script_php/insert/insert_article.php',$scope.dataInsert)
                 .success(function(data,status,header,config){
                   if (status==200) {
                     console.log('GOOD');
                     console.log($scope.dataInsert);
                   } else {
                     console.log('not good');
                   }
                 })
               }

这里的问题如何绑定我的textarea(CKEDITOR)的数据我跳了解你,谢谢你。

1 个答案:

答案 0 :(得分:0)

正如您在此代码段中看到的,绑定实际上正在运行:

&#13;
&#13;
 function MyController($scope, $http) {
 $scope.insertArticle = function(){
  alert($scope.editor1);
 };
}
&#13;
<div ng-app ng-controller="MyController">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<textarea name="editor1" ng-model="editor1"  id="editor1" rows="10" cols="80"></textarea>

<button type="submit" class="button expand success" ng-click="insertArticle()">Save</button>
</div>
&#13;
&#13;
&#13;

我认为你的问题是由于编码错误而导致你没有在PHP端得到​​帖子的正文。你应该明确地将编码设置为x-www-form-urlencoded,特别是如果你的后端在PHP中:

$http.post('script_php/insert/insert_article.php',$.param($scope.dataInsert), {headers: {'Content-Type': 'application/x-www-form-urlencoded'}})