我看过很多对 AngularJS 的引用 链接前和链接后功能 在有关 AngularJS 的文献中。
但是,我不确定这些是否可以自定义或在框架内部。
换句话说,作为一个 AngularJS 开发者,我可以提供我自己的 前后链接功能到我的自定义指令?
最佳答案
是的,你可以,根据@Mikke 的回答。总结起来,链接函数的声明方式有四种:
compile
指定两者 preLink
和 postLink
明确的功能:compile: function compile(tElement, tAttrs, transclude) {
return {
pre: function preLink(scope, iElement, iAttrs, controller) { ... },
post: function postLink(scope, iElement, iAttrs, controller) { ... }
}
}
compile
仅返回 postLink
隐含地:compile: function compile(tElement, tAttrs, transclude) {
return function postLink( ... ) { ... }
}
link
指定两者 preLink
和 postLink
明确地:link: {
pre: function preLink(scope, iElement, iAttrs, controller) { ... },
post: function postLink(scope, iElement, iAttrs, controller) { ... }
}
link
使用 postLink
隐含地:link: function postLink( ... ) { ... }
关于angularjs - AngularJS 指令前链接和后链接功能可以自定义吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22105336/