Problem at angular 1.5 running with minified files

Asked

Viewed 178 times

1

I have a project with Angularjs 1.5 running on my machine debug mode, I went to generate a release so I ran Gulp to minify the files and started the problems I made several adjustments and now I have this error: "Error: [$sce:unsafe] http://errors.angularjs.org/1.5.5/$sce/unsafe"

I do not know what to do because in normal file works and in minificado no, someone knows what error is this?

  • You’re wearing something like that ng-bind-html=... in your project?

  • I have an excerpt that I use yes, I was reading now that this may give error, if that is the case what the best way to use it?

2 answers

2


The problem is caused when you try to apply a text bind in html mode, i.e. ng-bind-html without the use of the module ngSanitize, which is responsible for 'lapidar', shall we say, this text for the same is displayed.

There are some "fixes" that you create a directive to circumvent this error so that you apply the bind "unsafe" mode. But the most correct way would be to initialize the module ngSanitize Angular itself in its application. It is a common boot like any other module.

//Inclua o script como achar melhor, ex.:
<script src="//ajax.googleapis.com/ajax/libs/angularjs/X.Y.Z/angular-sanitize.js"></script>

and in your module do the boot:

angular.module('app', [
    //Seus outros módulos aqui
    'ngSanitize'
]);

Edited

How these options (and our talk in the comments) did not solve the problem - which is very strange - this one would be the alternative fix I mentioned:

angular.module('gaxApp')
.filter('trust_html', ['$sce', function($sce){
    return function(text) {
        return $sce.trustAsHtml(text);
    };
}]);

Being used thus:

ng-bind-html="seucampo | trust_html"
  • I’m doing this so I’m finding it strange! I put "ngSanitize" on startup and import its version via CDN

  • @Diogosoares how are you doing the bind? can put the code as an example?

  • The initialization of the module looks like this: angular&#xA; .module('gaxApp', [&#xA; 'ngAnimate',&#xA; 'ngResource',&#xA; 'ngSanitize'&#xA; ]) In my html it looks like this: <div data-ng-bind-html="fornecimentoCtrl.breadcrumb"></div>

  • @Diogosoares Try to remove the data- bind. If not solve, try this way: ng-bind-html-unsafe

  • put ng-bind-html-unsafe did not present the error but also did not show the value, had not passed this before, hehehehe

  • @Diogosoares man, how strange... I will edit the answer with an alternative fix..

  • For this case of ng-bind-html I have now managed to put $sce in the controller so I put my html inside the $sce.trustAsHtml method but it didn’t work for the . Components I have on the screen is a good practice to use $sce?

  • @Diogosoares I confess that I never needed to use. Just add the module sanitize that would solve the problem. I don’t know why yours isn’t working... weird.. But I’ve seen some examples using $sce, which is also what I did in editing my answer, but more dynamically.

Show 3 more comments

0

I was able to solve the problem that made ngSanitize not work. The problem was because I was loading the login page without ngSanitize to after logging in I called another page that I was loading but the ng-apps had the same name and for some reason ngSanitize was not initialized, I’ve sorted everything neatly with other names and it’s working 100% now. Thanks for the help!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.