首页 > 网站 > WEB开发 > 正文

$sce服务----- 将请求到的html代码 引入到项目中

2024-04-27 15:05:38
字体:
来源:转载
供稿:网友
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script type="text/javascript" src="../angular.min.js"></script> </head> <body> <div ng-app="myApp"> <div ng-controller="firstController"> {{name}} <div ng-bind-html="detailContent()"></div> </div> </div> <script type="text/Javascript"> var app = angular.module("myApp", []); app.controller('firstController',function($scope,$timeout,$sce,$http){ $scope.name = 'hello'; $scope.text = '<h1>hello</h1>'; var myUrl = "http://www.phonegap100.com/appapi.php?a=getPortalArticle&aid=338&callback=JSON_CALLBACK"; $http.jsonp(myUrl).success( function(data){ //$scope.portalDetail = data.result[0]; $scope.detailContent = function() { return $sce.trustAsHtml(data.result[0].content); }; } ).error(function(){ alert('失败'); }); }); </script> </body> </html>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表