【问题标题】:AngularJS Navigation does not work after tinymce directivetinymce 指令后 AngularJS 导航不起作用
【发布时间】:2012-07-09 07:29:48
【问题描述】:

我有问题我无法弄清楚,但我确实有一个提示。在集成 TinyMCE 之前,主导航运行良好,例如链接设置、分析、设置;如果您单击它们,它现在不起作用。

这是我的 js 文件:

var app_htmleditor_module = angular.module('app_htmleditor', ['components']).
    config(['$routeProvider', function($routeProvider) {
        $routeProvider.
            when('/', {templateUrl: getBaseURL()+'public/tpl/app/htmleditor.htm',   controller: HtmlEditorCtrl, reloadOnSearch:false }).
            otherwise( {redirectTo: '/'});
    }
]);
    
angular.module('components', []).directive('imageUpload', function () {
    return {
        restrict: 'E',
        scope: {
              uploaderid:'@uploaderid'
            },
        templateUrl: '/public/tpl/imageupload.htm'
    }
});
        
app_htmleditor_module.directive('uiTinymce', function() {
     return {
         
         require: 'ngModel',
         link: function(scope, element, attrs, ngModel) {
             
             element.tinymce({
                 // Location of TinyMCE script
                 script_url: 'http://resources.holycrap.ws/jscripts/tiny_mce/tiny_mce.js',

                 // General options
                 theme: "simple",

                 // Change from local directive scope -> "parent" scope
                 // Update Textarea and Trigger change event
                 // you can also use handle_event_callback which fires more often
                 onchange_callback: function(e) {

                     if (this.isDirty()) {
                         this.save();

                         // tinymce inserts the value back to the textarea element, so we get the val from element (work's only for textareas)
                         //ngModel.$setViewValue(e.getBody().innerHTML);
                         ngModel.$setViewValue(element.val());
                         scope.$apply();
                         
                         return true;
                     }
                 }
             });

         }
     }
});

然后我使用 ui:tinymce 将上面的 tinymce 指令添加到 textarea 中,如下所示:

<textarea ui:tinymce ng-model="data.html_tab" id="{{fileUploaderID}}_html_tab" name="{{fileUploaderID}}_html_tab" style="width:600px; height:300px"></textarea>

请注意上面的ui:tinymce。如果我删除它,导航会再次正常工作。那么如何使用在 textarea 中添加的ui:tinymce 使我的导航工作?

演示网址:

http://dev-socialapps.rkm-group.com/app/htmleditor/index#/

任何帮助将不胜感激。谢谢

更新:

按照建议,我先将 ui js 文件添加到我的模板文件中:

<script src="https://raw.github.com/angular-ui/angular-ui/master/build/angular-ui.js"></script>

然后在我的js文件中,我添加了:

var app_htmleditor_module = angular.module('app_htmleditor', ['components', 'ui']).
    config(['$routeProvider', function($routeProvider) {
        $routeProvider.
            when('/', {
                templateUrl: getBaseURL()+'public/tpl/app/htmleditor.htm',
                controller: HtmlEditorCtrl,
                reloadOnSearch:false
            }).
            otherwise( {redirectTo: '/'});
    }
]);

app_htmleditor_module.value('ui.config', {
   tinymce: {
      theme: 'simple'
   }
});

在textarea标签中:

<textarea ui-tinymce ng-model="tinymce" id="{{fileUploaderID}}_html_tab" name="{{fileUploaderID}}_html_tab" style="width:600px; height:300px"></textarea>

但我收到错误:

ReferenceError: tinymce is not defined

虽然ui js文件添加得很好,但我通过查看源代码并点击链接确认

【问题讨论】:

    标签: javascript tinymce angularjs


    【解决方案1】:

    您是否尝试过 angular-ui 库中最新版本的 tinymce 指令?

    Demo

    JS file

    【讨论】:

    • 感谢您的回复。我不确定我只是从这里获取示例代码:jsfiddle.net/ProLoser/nTzRA/light
    • 我只是在使用这个文件(例如没有 ui):angular-1.0.1.js
    • 用最新版本试试吧,希望可以。您找到的版本可能已过时/不再工作。要快速测试,只需将&lt;script src="https://raw.github.com/angular-ui/angular-ui/master/build/angular-ui.js"&gt;&lt;/script&gt; 添加到您的HTML 并编辑您的模块声明以将ui 添加到您的应用程序:angular.module('myApp', ['ui']);。然后你可以尝试像示例中那样做 ui-tinymce。
    • 试过了,但出现错误,请查看更新后的问题及详细信息
    • 啊,请确保您也包含 tinymce js 文件。 &lt;script src="https://raw.github.com/tinymce/tinymce/master/jscripts/tiny_mce/tiny_mce_dev.js"&gt;&lt;/script&gt;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-30
    • 1970-01-01
    • 2017-01-23
    • 2013-04-27
    • 2014-12-07
    • 1970-01-01
    相关资源
    最近更新 更多