Javascript AngularJS:如何将JSONP数据呈现为HTML
我对$http的概念相当陌生,并且尝试从不同的站点检索数据。我的问题是。如何将JSONP呈现为HTML?在我的$http中,我请求Atari Wikipedia页面。页面正在显示包含HTML元素的内容。我如何才能渲染数据,使其正确渲染Javascript AngularJS:如何将JSONP数据呈现为HTML,javascript,angularjs,Javascript,Angularjs,我对$http的概念相当陌生,并且尝试从不同的站点检索数据。我的问题是。如何将JSONP呈现为HTML?在我的$http中,我请求Atari Wikipedia页面。页面正在显示包含HTML元素的内容。我如何才能渲染数据,使其正确渲染 var-app=angular.module('app',[]); app.controller('DataCtrl',['$scope','$http', 函数($scope,$http){ //$scope.list; var url='1〕http://e
var-app=angular.module('app',[]);
app.controller('DataCtrl',['$scope','$http',
函数($scope,$http){
//$scope.list;
var url='1〕http://en.wikipedia.org/w/api.php?titles=atari&rawcontinue=true&action=query&format=json&prop=extracts&callback=JSON_CALLBACK';
$http.jsonp(url).success(函数(数据){
$scope.info=data.query.pages[2234]。提取;
}).错误(函数(数据){
$scope.data=“错误”;
});
}
]);代码>
{{info}}
如果您只想显示html,那么可以在页面上使用ng bind html
指令从范围变量绑定html,但也需要$sce.trustAsHtml
来清理html。您还需要使用angular sanitize.js
标记
<div ng-bind-html="trustedHtml(info)"></div>
如果您只想显示html,那么可以使用页面上的ng bind html
指令从范围变量绑定html,但也需要$sce.trustAsHtml
来清除html。您还需要使用angular sanitize.js
标记
<div ng-bind-html="trustedHtml(info)"></div>
我将尝试通过$sce.trustAsHtml
函数传递它,并使用ng bind html显示它:
var app = angular.module('app', []);
app.controller('DataCtrl',['$scope','$http', '$sce',function($scope,$http, $sce){
// $scope.list;
var url = 'http://en.wikipedia.org/w/api.php?titles=atari&rawcontinue=true&action=query&format=json&prop=extracts&callback=JSON_CALLBACK';
$http.jsonp(url).success(function(data){
$scope.info = $sce.trustAsHtml(data.query.pages[2234].extract);
}).error(function(data){
$scope.data = "Error";
});
}]);
别忘了读相关的
如果没有任何额外的检查,这将使您的系统易受攻击。(XSS和类似的东西)我会尝试通过$sce.trustAsHtml
函数传递它,并使用ng bind html显示它:
var app = angular.module('app', []);
app.controller('DataCtrl',['$scope','$http', '$sce',function($scope,$http, $sce){
// $scope.list;
var url = 'http://en.wikipedia.org/w/api.php?titles=atari&rawcontinue=true&action=query&format=json&prop=extracts&callback=JSON_CALLBACK';
$http.jsonp(url).success(function(data){
$scope.info = $sce.trustAsHtml(data.query.pages[2234].extract);
}).error(function(data){
$scope.data = "Error";
});
}]);
别忘了读相关的
如果没有任何额外的检查,这将使您的系统易受攻击。(XSS和类似的东西)指令ng bind html工作得很好,正如前面所解释的,但它只是为了显示数据而有用,如果您想在控制器中操作数据,那么您可以使用$sanitize(html)代码>指令ng bind html工作正常,正如前面所解释的那样,但它对于显示数据非常有用,如果您想在控制器中操作数据,则可以使用$sanitize(html)代码>这对我来说很有效!我很感激拉乔斯的帮助!这对我来说是成功的!我很感激拉乔斯的帮助!