gpt4 book ai didi

javascript - angularjs,需要帮助理解 $compile 函数

转载 作者:行者123 更新时间:2023-11-30 12:23:12 25 4
gpt4 key购买 nike

我找到了一个很好的工作示例来显示 AngularJS 的文件树: http://jsfiddle.net/n8dPm/

我正在尝试理解代码。我不清楚这里发生了什么:

var compiledContents;
return function(scope, iElement, iAttr) {
if(!compiledContents) {
compiledContents = $compile(contents);
}

compiledContents(scope, function(clone, scope) {
iElement.append(clone);
});

对我来说,似乎首先使用 compiledContents 来编译内容,然后将 compiledContents 作为函数调用?

谁能解释一下?

最佳答案

函数可以返回 Javascript 中的函数。

注意 documentation for $compile ,它说:

Compiles an HTML string or DOM into a template and produces a template function, which can then be used to link scope and the template together.

关于javascript - angularjs,需要帮助理解 $compile 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30352110/

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