1

angularjs バージョン 1.3.13、ui-bootstrap-tpls バージョン 0.12、angularjs ui ルーター バージョン 0.2.13 を使用しています。ui-sref を使用して、アコーディオン内のテンプレート コンテンツを表示したいです。アコーディオン内のテンプレートが読み込まれた後、チェックボックス コンポーネントのクリック イベントがトリガーされません。見つかったイベントは、ボタンを除くすべての要素に対して以下の場所で防止されます この解決策が正しいかどうか教えてください。
私のコードを以下に示します。

<accordion>
  <accordion-group is-open="true" ui-sref="addContract.add">
    <accordion-heading>
      Settings <i class="pull-right glyphicon" 
                  ng-class="{'glyphicon-chevron-down': $state.includes('true'), 'glyphicon-chevron-down': !status.open}"></i>
    </accordion-heading>
  <div ui-view="kpiParamSettings" autoscroll="true"></div>
</accordion-group></accordion>

ui-sref には次の html があります

<div>
  <label><input id="login-remember" name="remember" type="checkbox" value="1">Stop</label>
</div>
element.bind("click", function(e) {
        var button = e.which || e.button;
        if ( !(button > 1 || e.ctrlKey || e.metaKey || e.shiftKey || element.attr('target')) ) {
          // HACK: This is to allow ng-clicks to be processed before the transition is initiated:
          var transition = $timeout(function() {
            $state.go(ref.state, params, options);
          });
          e.preventDefault();

          // if the state has no URL, ignore one preventDefault from the <a> directive.
          var ignorePreventDefaultCount = isAnchor && !newHref ? 1: 0;
          e.preventDefault = function() {
            if (ignorePreventDefaultCount-- <= 0)
              $timeout.cancel(transition);
          };
        }
      });

上記のクリックイベントで、次の条件を追加しました

    element.bind("click", function(e) {
if(e.target.type!="checkbox") // Condition for avoiding to bind the checkbox click event
      {
            var button = e.which || e.button;
            if ( !(button > 1 || e.ctrlKey || e.metaKey || e.shiftKey || element.attr('target')) ) {
              // HACK: This is to allow ng-clicks to be processed before the transition is initiated:
              var transition = $timeout(function() {
                $state.go(ref.state, params, options);
              });
              e.preventDefault();

              // if the state has no URL, ignore one preventDefault from the <a> directive.
              var ignorePreventDefaultCount = isAnchor && !newHref ? 1: 0;
              e.preventDefault = function() {
                if (ignorePreventDefaultCount-- <= 0)
                  $timeout.cancel(transition);
              };
            }
}
          });
4

2 に答える 2

1

を使用しelement.bindてもダイジェスト サイクルがトリガーされないため、UI は更新されません。ngClickを使用するか、クリック ハンドラーに追加$scope.$apply()して、ダイジェスト サイクルを手動でトリガーします。

于 2015-04-20T13:32:34.660 に答える
0

次のアコーディオン宣言を使用して、上記の問題を修正しました。

私のコードは

<accordion>
   <accordion-group is-open="true" ui-sref="addContract.add"> 
     <accordion-heading>
    Settings <i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': $state.includes('true'), 'glyphicon-chevron-down': !status.open}"></i>
     </accordion-heading>
      <div ui-view="kpiParamSettings" autoscroll="true"></div>
   </accordion-group>   
</accordion>

コードを編集した後、問題は修正されました

<accordion>
   <accordion-group is-open="true"> // Removed ui-sref from this line
     <accordion-heading>
        <a ui-sref="addContract.add"> // Added a with ui-sref
            Settings <i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': $state.includes('true'), 'glyphicon-chevron-down': !status.open}"></i>
        </a>
     </accordion-heading>
      <div ui-view="kpiParamSettings" autoscroll="true"></div>
   </accordion-group>   
</accordion>
于 2015-04-21T04:37:05.403 に答える