Angular.js: $$ tlbは滞在/公式になりますか?

作成日 2014年01月29日  ·  3コメント  ·  ソース: angular/angular.js

ドキュメントにないので、ディレクティブで使用することには少し注意が必要です。

ただし、場合によっては複数のトランスクルージョンを実行できるようにしたいので、使用する必要があります。

だからそこにあります; 将来、ディレクティブが壊れることを恐れずに安全に使用できますか?

最も参考になるコメント

将来、同じ要素で複数のトランスクルージョンを許可する何らかのオプションはありますか?
私はこれが役立つであろう多くの領域を見ることができます-それは私のディレクティブのいくつかにとって実際にはかなり重要です、そこで私はコンパイル関数でDOMと$ compileをいじくり回しました(これはきれいなtbhを感じません)

全てのコメント3件

このAPIに依存しないでください。 $$はプライベートであることを意味し、将来のリリースで壊れる可能性があります。

将来、同じ要素で複数のトランスクルージョンを許可する何らかのオプションはありますか?
私はこれが役立つであろう多くの領域を見ることができます-それは私のディレクティブのいくつかにとって実際にはかなり重要です、そこで私はコンパイル関数でDOMと$ compileをいじくり回しました(これはきれいなtbhを感じません)

カスタムディレクティブでngIfスタイルの動作を実装できると間違いなく役立ちます。 このようなディレクティブを作成するのは、要素のレンダリングのみを目的として、常にサービスを挿入したり、コントローラーのプロパティを作成したりする必要がないようにするためです。

ngIfと同じように機能させるために、内部ディレクティブプロパティに依存する必要がないことは間違いありません。

例えば:

import {SubscriptionService, ISubscription} from '../subscriptions/subscriptions.service';

interface IPBIfFeatureDirectiveScope extends ng.IScope {
  isRenderElement: boolean;
}

interface IPBIfFeatureDirectiveAttributes extends ng.IAttributes {
  pbIfFeature: string;
  ngIf: string;
}

class IfFeatureDirective implements ng.IDirective {

  public transclude: any;
  public priority: number;
  public terminal: boolean;
  public restrict: string;
  public scope = true;
  public link: ng.IDirectiveLinkFn;
  public $$tlb: boolean;

  constructor(ngIfDirectiveArr: ng.IDirective[],
              subscriptionService: SubscriptionService,
              $parse: ng.IParseService) {

    let ngIfDirective: any = ngIfDirectiveArr[0];

    this.transclude = ngIfDirective.transclude;
    this.priority = ngIfDirective.priority - 1;
    this.terminal = ngIfDirective.terminal;
    this.restrict = ngIfDirective.restrict;
    this.$$tlb = true;
    this.link = function (scope: IPBIfFeatureDirectiveScope,
                          element: ng.IAugmentedJQuery,
                          attr: IPBIfFeatureDirectiveAttributes) {
      let expression: string = attr.pbIfFeature;
      let argArray: IArguments = arguments;
      let executeDirective = (): void => {
        subscriptionService.getSubscription().$promise
          .then((subscription: ISubscription) => {
            scope.isRenderElement = $parse(expression)(subscription.features);
            attr.ngIf = 'isRenderElement';
            ngIfDirective.link.apply(null, argArray);
          });
      };
      executeDirective();
    };
  }
}
export const ifFeatureDirectiveFactory = (ngIfDirective: ng.IDirective[],
                                          subscriptionService: SubscriptionService,
                                          $parse: ng.IParseService): ng.IDirective => new IfFeatureDirective(ngIfDirective, subscriptionService, $parse);
ifFeatureDirectiveFactory.$inject = ['ngIfDirective', 'subscriptionService', '$parse'];
このページは役に立ちましたか?
0 / 5 - 0 評価