Como não está nos documentos, tenho um pouco de receio de usá-lo em minhas diretivas.
No entanto, estou precisando usá-lo, pois gostaria de poder fazer transclusões múltiplas em alguns casos.
Então é isso; posso usá-lo com segurança, sem medo de ver minhas diretivas serem quebradas no futuro?
Não confie nesta API. $$
significa que é privado e podemos quebrá-lo em uma versão futura.
Haverá algum tipo de opção para permitir a transclusão múltipla no mesmo elemento no futuro?
Eu posso ver muitas áreas onde isso seria útil - na verdade é muito importante para algumas de minhas diretivas, onde fui reduzido a mexer no DOM e $ compile na função de compilação (que não parece limpa tbh)
Definitivamente, seria útil ser capaz de implementar o comportamento do estilo ngIf em diretivas personalizadas. Nós criamos tais diretivas para que não tenhamos que injetar serviços constantemente e criar propriedades de controlador somente com o propósito de renderização de elemento.
Eu definitivamente preferiria não ter que depender de uma propriedade de diretiva interna para fazê-la funcionar da mesma forma que o ngIf.
Por exemplo:
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'];
Comentários muito úteis
Haverá algum tipo de opção para permitir a transclusão múltipla no mesmo elemento no futuro?
Eu posso ver muitas áreas onde isso seria útil - na verdade é muito importante para algumas de minhas diretivas, onde fui reduzido a mexer no DOM e $ compile na função de compilação (que não parece limpa tbh)