-1

I want to escape special characters and html while saving to database , Can i use filter to achieve that task with below code i am getting an error your module is not loaded properly, Do i need to add dependeny in app.js. New to AngularJs any help will be appreciated.

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.
8
  • 2
    Where is your riskAssessmentApp? Commented Feb 22, 2016 at 15:11
  • I added app.js please take a look Commented Feb 22, 2016 at 15:14
  • Do you think i added ng-bind-html correctly with tooltip and everything ? Commented Feb 22, 2016 at 15:17
  • That won't cause the error .... but ng-bind-html won't do anything on textarea. The module error is not view related at all Commented Feb 22, 2016 at 15:17
  • If i understand correctly so i should not add ng-bind-html to textarea Commented Feb 22, 2016 at 15:19

1 Answer 1

2

You define riskAssessmentApp module twice.

In your filter.js don't redefine it, just attach the filter to that module:

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];
      }));
    }
  });
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.