【问题标题】:How to fix this error: [$sce:itype] in AngularJS 1.6?如何修复此错误:AngularJS 1.6 中的 [$sce:itype]?
【发布时间】:2017-08-30 12:56:34
【问题描述】:

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

错误:[$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 [...]

主控制器

(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

标签: javascript angularjs http


【解决方案1】:

$sce:itype 错误发生在您尝试信任需要字符串的内容中的非字符串值


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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-22
    • 2014-03-01
    • 2012-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多