Angularjs 如何在angular js中解析字符串内的html标记
在控制器中,我有一个变量,比如$scope.questionAngularjs 如何在angular js中解析字符串内的html标记,angularjs,Angularjs,在控制器中,我有一个变量,比如$scope.question $scope.question = "Hi this is <br/> book"; $scope.question=“您好,这是一本书”; 在html页面中,像{{question}一样访问这个变量 <div class="question"> 1. {{question}} </div> 1.{{问题} 我想要带换行符的输出。。。但它显示为字符串。。。如何解析html标
$scope.question = "Hi this is <br/> book";
$scope.question=“您好,这是一本书”;
在html页面中,像{{question}一样访问这个变量
<div class="question">
1. {{question}}
</div>
1.{{问题}
我想要带换行符的输出。。。但它显示为字符串。。。如何解析html标记。您应该使用
ng bind html
指令。要利用这一点,您需要:
//1. given
.controller('AppController', [
function() {
$scope.SomeHtml = '<b>some html</b>';
//2. use ng-bind
<div ng-bind-html="SomeHtml"></div>
//1。鉴于
.controller('AppController'[
函数(){
$scope.SomeHtml='SomeHtml';
//2.使用ng绑定
检查演示。如果我们的文本包含一些html内容,那么我们必须在angular js中使用ng bind html指令,否则我们的html内容将不会被解析,而是按原样呈现 例如: 如果我们的文本是
$scope.Val = "<span> Something </span>"
希望它有助于……!可能的副本
<div> {{Val}} </div>
<div ng-bind-html="Val"></div>
var app = angular.module('myApp', ['ngSanitize']);