在transclude结束后触发方法

时间:2014-10-28 16:20:09

标签: angularjs angularjs-directive

我有一个Angular指令,用<ol><li>元素创建一个手风琴,每个<li>的内容都包含在一个被转换的模板中。我需要触发一个方法来检查这些<li>元素中是否有任何错误,然后打开那个手风琴,但是我无法在之后找到一种方法来触发方法元素已被抄袭。

是否有正确计时的钩子或指令配置?

1 个答案:

答案 0 :(得分:2)

我想你可以访问指令定义对象中定义的postLink函数中的内容。检查官方documentation

使用指令定义对象可以定义:

compile: function compile(tElement, tAttrs, transclude) {
  return {
    pre: function preLink(scope, iElement, iAttrs, controller) { ... },
    post: function postLink(scope, iElement, iAttrs, controller) { ... }
  }
  // or
  // return function postLink( ... ) { ... }
},

在那里你可以注入和访问iElement及其内容。这在模板编译后发生,因此<li>元素应该已经存在。