如何修复 AngularJS 1.6 中的 [$sce:itype] 错误?

4
我正在使用AngularJS 1.6.4,遇到了关于$sce的错误:

错误:[$sce:itype] http://errors.angularjs.org/1.6.4/$sce/itype?p0=html 堆栈跟踪: 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 [...]

主控制器
(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);

我不理解这个错误的含义。有人能解释一下吗?我该怎么修复它?

请发布您的response - Maxim Shoustin
1个回答

5

$sce:itype 错误发生在您试图信任非字符串值的内容需要字符串的情况下。


在成功回调中,response 对象很可能不是 HTML 代码。因此,在尝试使用 $sce 将其信任为 HTML 时会失败。

检查 response 对象,可能有一个包含您的 HTML 代码的 response.data


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接