Angularjs输出html
2016-05-10 22:26
671 查看
第一种方式 ng-bind-html
html
angularjs
只需要改变$scope.content的值为要输出的html就可以输出被浏览器解析的html代码,但是如果代码中有ng-model或者ng-click这种绑定的方法和对象,not-working
这时候改用第二种方式:compile
html
angularjs
运行一下,完美的解决了问题。
html
<div id="popup" ng-bind-html="popup.content | to_trusted"></div>
angularjs
app.filter('to_trusted', ['$sce', function ($sce) { return function (text) { return $sce.trustAsHtml(text); }; }])
只需要改变$scope.content的值为要输出的html就可以输出被浏览器解析的html代码,但是如果代码中有ng-model或者ng-click这种绑定的方法和对象,not-working
这时候改用第二种方式:compile
html
<div id="popup" compile="popup.content"></div>
angularjs
app.directive('compile', ['$compile', function ($compile) { return function(scope, element, attrs) { scope.$watch( function(scope) { return scope.$eval(attrs.compile); }, function(value) { element.html(value); $compile(element.contents())(scope); } )}; }])
运行一下,完美的解决了问题。
相关文章推荐
- AngularJS 自定义控件
- angular中的transclude详解
- angular 身份认证问题
- angularjs学习总结一(表达式、指令、模型)
- AngularJS directive指令之require部分
- Angularjs实现分页和分页算法
- angular controller不执行
- webstorm查看angular2的ts源码
- Eclipse上安装angularjs插件
- 25个超有用的 AngularJS Web 开发工具
- AngularJS 的表单验证
- Angularjs中的ng-class
- AngularJs多重视图和路由的使用
- 如何使用 AngularJS 的 ngShow 和 ngHide
- Angularjs Directive(指令)机制
- Angularjs循环二维数组
- AngularJs: Reload page
- 创建 AngularJS 自定义过滤器,带自定义参数
- angularjs三级联动
- angularjs中动态为audio绑定src