小编kar*_*old的帖子

AngularJS:指令控制器中的$ transclude local和链接函数中的transclude参数之间有区别吗?

我实现了一个指令,将子内容的多个片段转换为模板.它的工作原理,但似乎比我见过的大多数例子都简单,并提出了一些关于如何进行翻译的问题.

这是指令:

module.directive('myTransclude', function() {
  return {
    restrict: 'A',
    transclude: true,
    replace: true,
    scope: true,
    template: '<div style="border: 1px solid {{color}}"><div class="my-transclude-title"></div><div class="my-transclude-body"></div></div>',
    link: function(scope, element, attrs, controller, transclude) {
      // just to check transcluded scope
      scope.color = "red";
      transclude(scope, function(clone, scope) {
        Array.prototype.forEach.call(clone, function(node) {
          if (! node.tagName) {
            return;
          }
          // look for a placeholder node in the template that matches the tag in the multi-transcluded content
          var placeholder = element[0].querySelector('.' + node.tagName.toLowerCase());
          if (! placeholder) {
            return; …
Run Code Online (Sandbox Code Playgroud)

angularjs angularjs-directive

8
推荐指数
1
解决办法
2172
查看次数

标签 统计

angularjs ×1

angularjs-directive ×1