2016-02-22 63 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

相關問題