【问题标题】:Integrate TextAngular into an application already using AngularJS将 TextAngular 集成到已经使用 AngularJS 的应用程序中
【发布时间】:2014-02-23 20:06:14
【问题描述】:

我正在尝试将 TextAngular 集成到我的网站中。

我已经在使用 AngularJs 和 UI 指令来实现其他功能,这些都可以正常工作,但是当我尝试添加 TextAngular 时,一切都崩溃了。

我在一个 Javascript 文件的顶部注册了我的模块,该文件是在 TextAngular 和 AngularJS 之后添加的,我在这里为 TextAngular 添加了代码:

angular.module('myApp', []);
angular.module('myApp', ['ui.bootstrap']);
//The above works for ui directives, I added this
angular.module('myApp', ['textAngular']);

我已经为文本角度添加了一个包:

bundles.Add(new ScriptBundle("~/bundles/textAngular").Include(
"~/Scripts/textAngular.js"));

这是我的编辑器代码:

<div ng-controller="wysiwygeditor" class="container app"">
    <h1>Editor</h1>
    <div text-angular="text-angular" name="htmlcontent" ng-model="htmlcontent"></div>
    <textarea ng-model="htmlcontent" style="width: 100%"></textarea>
    <div ng-bind-html="htmlcontent"></div>
    <div ta-bind="text" ng-model="htmlcontent"></div>
    <button type="button" ng-click="htmlcontent = orightml">Reset</button>
</div>

@Scripts.Render("~/bundles/textAngular")

<script type="text/javascript">
    function wysiwygeditor($scope) {
        $scope.orightml = '<h2>Try me!</h2>';
        $scope.htmlcontent = $scope.orightml;
    };
</script>

这是局部视图,_Layout 页面包含很多 twitter 引导内容。

就像我说的,AngularJS 和 UI 指令工作得很好,但是当我尝试在 TextAngular 中连接时,它就是不想工作。

我在 Chrome 中遇到的错误有点神秘:

错误:[$sce:unsafe] 试图在保险箱中使用不安全的值
语境。 errors.angularjs.org/1.2.2/$sce/unsafe
在 localhost:25332/Scripts/angular.js:78:12
在 htmlSanitizer localhost:25332/Scripts/angular.js:12162:13
在 getTrusted localhost:25332/Scripts/angular.js:12329:16
在 Object.sce.anonymous 函数 [as getTrustedHtml] localhost:25332/Scripts/angular.js:13027:16
在 Object.ngBindHtmlWatchAction [as fn] localhost:25332/Scripts/angular.js:16993:25
在 Scope.$digest localhost:25332/Scripts/angular.js:11501:27
在 Scope.$apply localhost:25332/Scripts/angular.js:11740:24
在 localhost:25332/Scripts/angular.js:1297:15
在 Object.invoke localhost:25332/Scripts/angular.js:3633:25
在 doBootstrap localhost:25332/Scripts/angular.js:1295:14

我在这里做错了什么?如果您需要查看更多代码,请发表评论。

谢谢

【问题讨论】:

    标签: c# javascript html asp.net-mvc angularjs


    【解决方案1】:

    您是否尝试过添加“textAngular-sanitize.js”文件: https://github.com/fraywing/textAngular#usage

    此文件旨在替换使用 textAngular 的项目中的“angular-sanitize.js”。 这是因为 angular-sanitize.js (ngSanitize) 过于严格,无法满足 textAngular 的需求: https://github.com/fraywing/textAngular#where-to-get-it (有注释)

    【讨论】:

      【解决方案2】:

      尝试在您的应用中添加 ngSanitize 作为依赖项。

      这里有更多信息:http://docs.angularjs.org/api/ngSanitize

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-10-29
        • 2015-02-26
        • 1970-01-01
        • 2018-06-24
        • 2014-08-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多