gpt4 book ai didi

javascript - 在 Angularjs 中渲染 HTML 和 CSS

转载 作者:行者123 更新时间:2023-11-28 07:50:55 24 4
gpt4 key购买 nike

如果我有一个带作用域的 Controller

$scope.post.description = "<style>#bo{font-weight:bold}</style> <h5 id='bo'> HI</h1> <p>My name is bamidele</p>";

如何在 View 中呈现它。它应该同时呈现 html 和 css

我试过了

$sce.trustAsCss($sce.trustAsHtml($scope.post.description));

但是没用

最佳答案

请检查这个工作示例:http://plnkr.co/edit/Guj3AuNrNNZ5F9EzkUxz?p=preview

下载文件 - angular-sanitize.js 并将其包含在您的应用中。

JS-

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

app.controller('myController', function($scope,$compile) {
$scope.html = '<p class="text-color">Your html code</p>';
});

HTML

<div ng-app="myApp">
<div ng-controller="myController">
<p ng-bind-html="html"></p>
</div>
</div>

CSS

.text-color {
color: #0000CC;
}

关于javascript - 在 Angularjs 中渲染 HTML 和 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30423962/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com