2016-02-22 62 views
-1

我想逃避特殊字符和HTML,同时保存到数据库,我可以使用筛选器来实现下面的代码与任务我得到一个错误您的模块没有正确加载,我需要在app.js.中添加依赖关系。新的AngularJs任何帮助将不胜感激。如何将html保存到数据库时转义html?

main.html中

<textarea rows="2" class="form-control" id="name" 
    ng-model="processDTO.processLongName" 
    placeholder="Business Process Name" maxlength="1024" name="processName" 
    required 
    ng-bind-html="escapeHtml" 
    data-tooltip-html-unsafe="<div>{{1024 - processDTO.processLongName.length}} characters left</div>" 
    tooltip-trigger="{{{true: 'focus', false: 'never'}[processDTO.processLongName.length >= 0 || processDTO.processLongName.length == null ]}}" 
    tooltip-placement="top" tooltip-class="bluefill"> 
</textarea> 

filter.js

angular 
    .module('riskAssessmentApp', [ 
    'ngSanitize' 
    ]) 
    .filter('escapeHtml', function ($sce) { 
    // Modified by Rockallite: Add $sce.trustAsHtml() to mute "Error: $sce:unsafe" 
    // http://stackoverflow.com/a/32835368/2293304 
    // http://stackoverflow.com/a/28537958/2293304 
    // https://github.com/janl/mustache.js/blob/master/mustache.js#L82 
    var entityMap = { 
     "&": "&amp;", 
     "<": "&lt;", 
     ">": "&gt;", 
     '"': '&quot;', 
     "'": '&#39;', 
     "/": '&#x2F;' 
    }; 

    return function(str) { 
     return $sce.trustAsHtml(String(str).replace(/[&<>"'\/]/g, function (s) { 
      return entityMap[s]; 
     })); 
    } 
    }); 

app.js

angular.module('riskAssessmentApp', [ 
    'angularSpinner', 
    'ngResource', 
    'ui.router', 
    'ngCookies', 
    'bacMultiselect', 
    'kendo.directives', 
    'kendoMultiselectTreeview', 
    'offClick', 
    'myMaxlength', 
    'requireControlPoint', 
    'disableControlPoint', 
    'disablePageElements', 
    'progressStepbar', 
    'ui.bootstrap', 
    'orcit.ssoHandler', 
    'orcit.icon', 
    'orcit.multiselectTreeview', 
    'orcit.loader' 
    'ngSanitize' 
]).config(function ($stateProvider, $httpProvider, $urlRouterProvider,$tooltipProvider) { 

ERROR

[$injector:nomod] Module 'riskAssessmentApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. 
+2

哪里是你的'riskAssessmentApp'? –

+0

我加了app.js请看看 – aftab

+0

你觉得我用tooltip和一切正确地加ng-bind-html吗? – aftab

回答

2

您定义了两次riskAssessmentApp模块。

在你filter.js不重新定义它,只是附加的过滤器的模块:

angular.module('riskAssessmentApp') 
    .filter('escapeHtml', function ($sce) { 
    // Modified by Rockallite: Add $sce.trustAsHtml() to mute "Error: $sce:unsafe" 
    // http://stackoverflow.com/a/32835368/2293304 
    // http://stackoverflow.com/a/28537958/2293304 
    // https://github.com/janl/mustache.js/blob/master/mustache.js#L82 
    var entityMap = { 
     "&": "&amp;", 
     "<": "&lt;", 
     ">": "&gt;", 
     '"': '&quot;', 
     "'": '&#39;', 
     "/": '&#x2F;' 
    }; 

    return function(str) { 
     return $sce.trustAsHtml(String(str).replace(/[&<>"'\/]/g, function (s) { 
      return entityMap[s]; 
     })); 
    } 
    }); 
+0

感谢您解决了一些问题。 – aftab

相关问题