如何在Javascript数组中添加HTML标记
我需要在我的Javascript数组中为大纲添加少量HTML。有没有一种方法可以在当前作为文本输出时执行此操作 到目前为止,我有下面的如何在Javascript数组中添加HTML标记,javascript,angularjs,Javascript,Angularjs,我需要在我的Javascript数组中为大纲添加少量HTML。有没有一种方法可以在当前作为文本输出时执行此操作 到目前为止,我有下面的 app.controller('primaryServiceListController', ['$scope', '$http', function($scope, $http){ $scope.serviceListings = [ { url: "details.html", img:
app.controller('primaryServiceListController', ['$scope', '$http', function($scope, $http){
$scope.serviceListings = [
{
url: "details.html",
img: "service-01.jpg",
sector: "Business",
synopsis: "Completely synergize resource taxing relationships <strong>via premier niche markets</strong>. Professionally cultivate one-to-one customer service robust."
}
]
}]);
app.controller('primaryServiceListController',['$scope','$http',函数($scope,$http){
$scope.serviceListings=[
{
url:“details.html”,
img:“service-01.jpg”,
部门:“商业”,
简介:“通过卓越的利基市场完全协同资源征税关系。专业培养一对一的客户服务。”
}
]
}]);
您需要在应用程序中包含,然后在模板中,您可以使用ng bind HTML
指令轻松绑定HTML:
<div ng-bind-html="serviceListings[0].synopsis"></div>
请参阅以下工作演示:
angular.module('app',['ngSanitize']))
.controller('ctrl',['$scope',函数($scope){
$scope.serviceListings=[{
url:“details.html”,
img:“service-01.jpg”,
部门:“商业”,
简介:“通过卓越的利基市场完全协同资源征税关系。专业培养一对一的客户服务。”
}]
}]);代码>
您可以将字符串呈现为html格式,如下所示:
<div ng-bind-html="serviceListings[0].synopsis"></div>
并在html文件中使用它
<div ng-bind-html="serviceListings[0].synopsis | trustHtml"></div>
您可以将其作为文本添加,然后在html中使用ng bind html
来呈现它
<element ng-bind-html="expression"></element>
“当前以文本形式输出”-这是什么意思?你能展示一下相关的html代码片段吗?我认为最好的做法是html应该在组件中,数组应该存储组件的名称(或引用),而不是html。如果HTML是在运行时生成的,则以这种方式构造组件。可能会复制为文本。。与通过卓越利基市场对关系征税一样,这个答案最有效。我有一个控制器的div,我将ng bind html添加到标记中。。因此
<element ng-bind-html="expression"></element>