| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>angular test</title>
- <style type="text/css">
- #editor-trigger {
- width: 100%;
- height: 200px;
- }
- </style>
- <link rel="stylesheet" type="text/css" href="../../dist/css/wangEditor.min.css">
- <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
- </head>
- <body>
-
- <div ng-app="editorContainer" ng-controller="editorCtrl">
- <p>wangEditor 集成到 angular 的示例</p>
- <div ng-model="text" contenteditable="true"></div>
- </div>
- <script type="text/javascript" src="../../dist/js/lib/jquery-1.10.2.min.js"></script>
- <script type="text/javascript" src="../../dist/js/wangEditor.js"></script>
- <script type="text/javascript">
- var app = angular.module('editorContainer', []);
- app.controller('editorCtrl', function ($scope) {
- $scope.editorContent = '';
- });
- app.directive('contenteditable', function() {
- return {
- restrict: 'A' ,
- require: '?ngModel',
- link: function(scope, element, attrs, ngModel) {
- // 初始化 编辑器内容
- if (!ngModel) {
- return;
- } // do nothing if no ng-model
- // Specify how UI should be updated
- ngModel.$render = function() {
- element.html(ngModel.$viewValue || '');
- };
- // Listen for change events to enable binding
- element.on('blur keyup change', function() {
- scope.$apply(readViewText);
- });
- // No need to initialize, AngularJS will initialize the text based on ng-model attribute
- // Write data to the model
- function readViewText() {
- var html = element.html();
- // When we clear the content editable the browser leaves a <br> behind
- // If strip-br attribute is provided then we strip this out
- if (attrs.stripBr && html === '<br>') {
- html = '';
- }
- ngModel.$setViewValue(html);
- }
-
- // 创建编辑器
- var editor = new wangEditor(element);
- editor.create();
- }
- };
- });
- </script>
- </body>
- </html>
|