有没有办法使用ng bind html绑定纯文本

有没有办法使用ng bind html绑定纯文本,html,angularjs,Html,Angularjs,我正在使用带有段落标记的ng绑定html。e、 g <p ng-bind-html="Message"></p> 当我在消息中获取html时,它按预期工作,但当它是纯文本时,它不会呈现消息。有人能解释一下原因吗?消息可能包含Html,也可能不包含Html。任何帮助都会很明显请尝试ngSanitize模块,尝试模块注入并查看其行为 <!DOCTYPE html> <html> <script src="https://ajax.googl

我正在使用带有段落标记的
ng绑定html
。e、 g

<p ng-bind-html="Message"></p>


当我在消息中获取html时,它按预期工作,但当它是纯文本时,它不会呈现消息。有人能解释一下原因吗?消息可能包含Html,也可能不包含Html。任何帮助都会很明显

请尝试
ngSanitize
模块,尝试模块注入并查看其行为

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular-sanitize.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">

<p ng-bind-html="myText"></p>

</div>

<script>
var app = angular.module("myApp", ['ngSanitize']);
app.controller("myCtrl", function($scope) {
    $scope.myText = "My name is: John Doe";
});
</script>

<p><b>Note:</b> This example includes the "angular-sanitize.js",
which has functions for removing potentially dangerous tokens from the HTML.</p>

</body>
</html>

var-app=angular.module(“myApp”,['ngSanitize']); app.controller(“myCtrl”,函数($scope){ $scope.myText=“我的名字是:John Doe”; }); 注意:此示例包括“angular sanitize.js”, 它具有从HTML中删除潜在危险标记的功能


尝试
ngSanitize
模块,尝试模块注入并查看其行为

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular-sanitize.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">

<p ng-bind-html="myText"></p>

</div>

<script>
var app = angular.module("myApp", ['ngSanitize']);
app.controller("myCtrl", function($scope) {
    $scope.myText = "My name is: John Doe";
});
</script>

<p><b>Note:</b> This example includes the "angular-sanitize.js",
which has functions for removing potentially dangerous tokens from the HTML.</p>

</body>
</html>

var-app=angular.module(“myApp”,['ngSanitize']); app.controller(“myCtrl”,函数($scope){ $scope.myText=“我的名字是:John Doe”; }); 注意:此示例包括“angular sanitize.js”, 它具有从HTML中删除潜在危险标记的功能


您可以使用trustAsHtml筛选器,而无需使用其他模块

演示

var-app=angular.module(“exApp”,“ngSanitize”);
应用程序控制器('ctrl',函数($scope,$sce){
$scope.message=$sce.trustAsHtml('您好,这是文本'+
“这是我的领域”);
$scope.messageplain=$sce.trustAsHtml(“Hellow”);
});

您可以使用trustAsHtml筛选器,而无需使用其他模块

演示

var-app=angular.module(“exApp”,“ngSanitize”);
应用程序控制器('ctrl',函数($scope,$sce){
$scope.message=$sce.trustAsHtml('您好,这是文本'+
“这是我的领域”);
$scope.messageplain=$sce.trustAsHtml(“Hellow”);
});