javascript - 如何修复此错误 : [$sce:itype] in AngularJS 1. 6?

标签 javascript angularjs http

我正在使用 AngularJS 1.6.4,我收到有关 $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 [...]

主控

(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);

我不明白这个错误是什么意思。有人可以解释我吗?我该如何解决?

最佳答案

$sce:type 当您试图信任需要字符串的内容中的非字符串值时,会发生错误。


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

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

关于javascript - 如何修复此错误 : [$sce:itype] in AngularJS 1. 6?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45961081/

相关文章:

javascript - 将函数作为两层深度的 props 传递

javascript - Selenium (Python): How to insert value on a hidden input?

javascript - 如何在应用制作工具中按月份对列表进行排序?

javascript - 修改 typescript 文件时,Angular2 在浏览器中没有变化

angularjs - 向 AngularJS 模型中数组的每个元素添加计算字段

java - 用于 HTTP POST、GET 等的最佳 Java 库是什么?

javascript - 在javascript中异步使用分块数据

angularjs - 带有 Angular2 的 ASP MVC Web api - Http header 访问控制

javascript - 在 Angular 中,如何将服务注入(inject) Controller ?

rest - HTTP 状态代码 当出现 java.sql.SQLException 时