AngularJS 能不能不用ng-bind-html绑定显示HTML
1 回答
Cats萌萌
TA贡献1805条经验 获得超9个赞
用{{}}是一定没法输出html的
不知道你项目里是怎么限制的不能使用 ng-bind-html
那你试试自己写个指令来实现一下好了
| 12345678910111213 | var app = angular.model('app' , []);app.directive('stringHtml' , function(){ return function(scope , el , attr){ if(attr.stringHtml){ scope.$watch(attr.stringHtml , function(html){ el.html(html || '');//更新html内容 }); } };});app.controller('TestCtrl' , function($scope){ $scope.string = '<button type="button">测试html按钮</button>';}); |
html:
| 123 | <div ng-controller="TestCtrl"> <span string-html="string"></span></div> |
- 1 回答
- 0 关注
- 852 浏览
添加回答
举报
0/150
提交
取消
