Angularjs-表示存储在$scope/model中的html和ng标记的指令
Angularjs - directive to present html and ng markup stored in $scope/model
我的场景是,我需要呈现来自数据库的HTML内容。HTML内容包含表达式和特定于ng的属性/元素。我已经被引导进入指令领域,但我不确定如何实现这一点,因为我无法访问可以返回模板字段的$scope:
var app = angular.module('app', []);
app.directive('dataPresenter', function () {
return {
restrict: 'AE',
replace: 'true',
template: ???How_To_Access $scope.data or the value of ng-model???
};
});
app.controller('Ctrl', function($scope) {
$scope.field = true;
$scope.data = "<b ng-if='field'>{{1+1}}</b>"
});
...
<div ng-controller="Ctrl">
<data-presenter ng-model="data"></data-presenter>
</div>
如果可以创建一个隔离作用域,那么可以在指令定义中添加一个scope
参数。scope参数用于定义应如何将数据传递给指令。
angularjs文档包括一个示例:http://plnkr.co/edit/ngdoc:example-example85@snapshot?p=预览
相关文章:
- 显示&作为&在jsp中使用angularjs而不使用ng-bind-html
- 如何根据html内容使用ng类-AngularJS
- ng绑定html不工作
- Angular 1.4解析ng-bind-html的内容
- 使用Jade输出HTML(在ng个重复内)
- 如何避免在HTML中使用ng repeat对url名称进行硬编码
- 在angular中,使用ng repeat生成动态html内容
- Angular.js:使用ng repeat创建2个html容器
- ng-bind-html 工作,但抛出错误
- AngularJs Datatables 无法使用 ng-repeat 在 html 上迭代列
- 为什么 HTML 中的 Value 属性在与 AngularJS 中的 ng-model 一起使用时不起作用
- 使用 ng-repeat将此 html 代码转换为角度
- AngularJS: ng-bind-html remove styling
- 为什么我的html节点保持类ng隐藏属性ng show=true
- angularjs-ng视图重新排列html元素
- 为什么我的指令是't使用ng-bind-html指令
- 如何使用“;ng如果“;在Html<a>标签
- 在我的HTML中用ng-init初始化$scope变量时出现问题
- 使用ng-html绑定时无法滚动
- angular js ng html in ng repeat won'不起作用