0

angularjs ディレクティブに頭を悩ませようとしています。親ディレクティブがあり、ページに 4 つのインスタンスがあります。親ディレクティブの 1 つに、CHILD ディレクティブのインスタンスが含まれています。

ただし、子ディレクティブのリンク関数は 4 回実行されているように見えますが、コンソールに次のように 4 回表示されます。

child linking function

理由/修正方法はありますか?ありがとう!

親:

Module.directive 'collapseWidget', () ->
  directive =
    restrict:   'A'
    transclude: true
    template:   viewCollapseWidget
    scope: 
      title:        '@title'
      widgetThemis: '@widgetThemis'
      color:        '@color'
      model:        '='

    #replace: true
    compile: (element, attrs, transclusionFunc) ->
      (scope, iterStartElement, attrs) ->

        #if scope.buttons
          #console.log scope.buttons
        scope.collapsed = false

        scope.toggle = () ->
          scope.collapsed = !scope.collapsed

        origElem   = transclusionFunc scope
        content    = origElem.text()
        scope.orig = content
        scope.obj  = content

子:

Module.directive "myTable", ->
      directive =
        restrict: 'A'
        scope: 'isolate'
        link: (scope, element, attrs) ->
          console.log 'child linking function'
          return
4

2 に答える 2

0

コンソール エラーが発生していますか?

私が尋ねる理由は、子の 'my​​Table' ディレクティブで、スコープが空のオブジェクトではなく文字列として定義されているためです。このため、スコープが分離されておらず、代わりに親スコープを使用している可能性があります。

于 2013-04-28T10:43:32.720 に答える