Angular.js: $$tlb 会留下/官方吗?

创建于 2014-01-29  ·  3评论  ·  资料来源: angular/angular.js

由于它不在文档中,所以我对在我的指令中使用它有点谨慎。

然而,我需要使用它,因为我希望在某些情况下能够进行多次嵌入。

所以它是; 我可以安全地使用它而不必担心将来看到我的指令被破坏吗?

最有用的评论

将来会有某种选项允许在同一元素上进行多次嵌入吗?
我可以看到很多地方这会很有用 - 它实际上对我的一些指令非常重要,在这些指令中我已经减少了在 compile 函数中摆弄 DOM 和 $compile (这感觉不干净tbh)

所有3条评论

请不要依赖此 API。 $$意味着它是私有的,我们可能会在未来的版本中打破它。

将来会有某种选项允许在同一元素上进行多次嵌入吗?
我可以看到很多地方这会很有用 - 它实际上对我的一些指令非常重要,在这些指令中我已经减少了在 compile 函数中摆弄 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 等级