angular ckeditor 编辑文字


先下载ckeditor

并且在index 中引用

  <script  src="lib/ckeditor/ckeditor.js"></script>


html 中代码:

  <form action="">
      <textarea ckeditor ng-model="dataAll122.Name" class="form-control" name="content"></textarea>

    </form>

    <button ng-click="clickAlert()">获得数据</button>

controller中代码:

  $scope.dataAll122 = {
      'Name': '',//
    };

 $scope.removeHTMLTag =  function (str) {
      str = str.replace(/<\/?[^>]*>/g,''); //去除HTML tag
      str = str.replace(/[ | ]*\n/g,'\n'); //去除行尾空白
      //str = str.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行
      str=str.replace(/ /ig,'');//去掉 
      str=str.replace(/\s/g,''); //将空格去掉
      return str;
    }

//获取纯文本
    $scope.clickAlert = function(){
      console.log("-------");
      console.log($scope.dataAll122.Name);
     $scope.xudesong =  $scope.dataAll122.Name,

       $scope.xudesong= $scope.removeHTMLTag( $scope.dataAll122.Name);
      console.log( $scope.xudesong);
    }

directive 中的代码

.directive('ckeditor', function() {
  return {
    require : '?ngModel',
    link : function(scope, element, attrs, ngModel) {
      var ckeditor = CKEDITOR.replace(element[0], {

      });
      if (!ngModel) {
        return;
      }
      ckeditor.on('instanceReady', function() {
        ckeditor.setData(ngModel.$viewValue);
      });
      ckeditor.on('pasteState', function() {
        scope.$apply(function() {
          ngModel.$setViewValue(ckeditor.getData());
        });
      });
      ngModel.$render = function(value) {
        ckeditor.setData(ngModel.$viewValue);
      };
    }
  };
});




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值