【发布时间】:2014-11-08 15:40:22
【问题描述】:
我是 Angular JS 的新手,试图理解如下编写的指令功能
function mydirective($interpolate, $compile) {
return {
restrict: 'E',
scope: {
mycontent: '=',
myurls: '=',
mydata: '@'
},
replace: true,
template: '<div ng-bind-html="html"></div>',
link: function ($scope, element, attrs) {
$scope.$watch('mycontent', function (value) {
var html = $interpolate(value)($scope);
element.html(html);
$compile(element.contents())($scope);
});
}
}
}
我无法从上面理解以下内容。
1) 这个 $interpolate(value)($scope) 做什么?第二个参数 $scope 是什么。
2) 这个 $compile 函数在做什么?
3) 模板中的 div ng-bind-html="html" 有什么作用?
【问题讨论】:
-
您阅读过函数文档吗? $interpolate 和 $compile
标签: javascript angularjs