Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix this error: [$sce:itype] in AngularJS 1.6?

I'm using AngularJS 1.6.4, I get this error concerning $sce:

Error: [$sce:itype] http://errors.angularjs.org/1.6.4/$sce/itype?p0=html Trace de la pile : L/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js:6:425 trustAs@https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js:155:46 [...]

Main Controller

(function(angular) {
    'use strict';
    angular.module('fooModule')
    .controller('MainCtrl', ['$scope', '$q', '$http', '$sce', function ($scope, $q, $http, $sce){
           ...
           $q.all([
            ...
        ]).then(function(responses) {
             $scope.send = function(){                                                           
                var data = {
                       ...
                    };

                    $http({
                        url: 'file.php',
                        method: "POST",
                        data: $.param(data),
                        headers: {'Content-Type': 'application/x-www-form-urlencoded'}
                    }).then(function successCallback(response) {
                        $scope.dataResponse = $sce.trustAsHtml(response);
                    }, function errorCallback(response) {
                        console.dir(response);
                    });
                }

            };
        });
           ...
     }]);
})(window.angular);

I don't understand what means this error. Someone can explain me ? How can I fix it ?

like image 714
J.BizMai Avatar asked Sep 20 '25 10:09

J.BizMai


1 Answers

$sce:itype error happens when you are attempted to trust a non-string value in a content requiring a string.


In the success callback, the response object is probably not HTML code. So it fails when trying to trust it as HTML using $sce.

Inspect the response object, there is probably a response.data that contains your HTML code.

like image 181
Mistalis Avatar answered Sep 23 '25 00:09

Mistalis