gpt4 book ai didi

javascript - Angular JS $插值查询

转载 作者:行者123 更新时间:2023-11-28 07:50:52 31 4
gpt4 key购买 nike

我是 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"它有什么作用?

最佳答案

What does this $interpolate(value)($scope) do?

获取value变量的文字值

what is this second argument $scope.

它提供数据绑定(bind)的上下文

it('should interpolate with undefined context', inject(
function($interpolate)
{
expect($interpolate("Hello, world!{{bloop}}")()).toBe("Hello, world!")
}
));

What is this $compile function doing?

它将字符串转换为 Angular 标记

div ng-bind-html="html" in template what does it do?

它编译 $scope.html 中的 HTML 字符串并将其添加到标记中

scope mapping

引用文献

关于javascript - Angular JS $插值查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26818849/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com