第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何使用$sce.TrustAsHtml(String)復(fù)制ng-bind-html-角1.2+中

如何使用$sce.TrustAsHtml(String)復(fù)制ng-bind-html-角1.2+中

慕村225694 2019-06-20 17:15:48
如何使用$sce.TrustAsHtml(String)復(fù)制ng-bind-html-角1.2+中的不安全ng-bind-html-unsafe移除角1.2我在努力實(shí)現(xiàn)我需要使用的東西ng-bind-html-unsafe..在文檔和GitHub提交文件中,他們說(shuō):Ng-bind-html提供了ng-html-綁定-不安全的類似行為(innerHTML的結(jié)果沒(méi)有衛(wèi)生化),當(dāng)綁定到$sce.TrustAsHtml(String)的結(jié)果時(shí)。你怎么做到的?
查看完整描述

3 回答

?
largeQ

TA貢獻(xiàn)2039條經(jīng)驗(yàn) 獲得超8個(gè)贊

這應(yīng)該是:

<div ng-bind-html="trustedHtml"></div>

加上你的控制器:

$scope.html = '<ul><li>render me please</li></ul>';$scope.trustedHtml = $sce.trustAsHtml($scope.html);

而不是舊的語(yǔ)法,您可以在其中引用$scope.html直接變量:

<div ng-bind-html-unsafe="html"></div>

正如幾位評(píng)論者所指出的,$sce必須在控制器中注入,否則您將得到$sce undefined錯(cuò)誤。

 var myApp = angular.module('myApp',[]);

 myApp.controller('MyController', ['$sce', function($sce) {
    // ... [your code]
 }]);


查看完整回答
反對(duì) 回復(fù) 2019-06-20
?
守著一只汪

TA貢獻(xiàn)1872條經(jīng)驗(yàn) 獲得超4個(gè)贊

濾光器

app.filter('unsafe', function($sce) { return $sce.trustAsHtml; });

使用

<ANY ng-bind-html="value | unsafe"></ANY>


查看完整回答
反對(duì) 回復(fù) 2019-06-20
?
qq_笑_17

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超7個(gè)贊

就我個(gè)人而言,在進(jìn)入數(shù)據(jù)庫(kù)之前,我使用一些PHP庫(kù)對(duì)所有數(shù)據(jù)進(jìn)行凈化,因此我不需要再使用XSS過(guò)濾器。

來(lái)自AngularJS 1.0.8

directives.directive('ngBindHtmlUnsafe', [function() {
    return function(scope, element, attr) {
        element.addClass('ng-binding').data('$binding', attr.ngBindHtmlUnsafe);
        scope.$watch(attr.ngBindHtmlUnsafe, function ngBindHtmlUnsafeWatchAction(value) {
            element.html(value || '');
        });
    }}]);

使用:

<div ng-bind-html-unsafe="group.description"></div>

禁用$sce:

app.config(['$sceProvider', function($sceProvider) {
    $sceProvider.enabled(false);}]);


查看完整回答
反對(duì) 回復(fù) 2019-06-20
  • 3 回答
  • 0 關(guān)注
  • 1046 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)