Add premium and unless-premium directives (#710)
This commit is contained in:
parent
744649573a
commit
f7375e9064
|
@ -0,0 +1,27 @@
|
|||
import { Directive, OnInit, TemplateRef, ViewContainerRef } from "@angular/core";
|
||||
|
||||
import { StateService } from "jslib-common/abstractions/state.service";
|
||||
|
||||
/**
|
||||
* Hides the element if the user has premium.
|
||||
*/
|
||||
@Directive({
|
||||
selector: "[appNotPremium]",
|
||||
})
|
||||
export class NotPremiumDirective implements OnInit {
|
||||
constructor(
|
||||
private templateRef: TemplateRef<any>,
|
||||
private viewContainer: ViewContainerRef,
|
||||
private stateService: StateService
|
||||
) {}
|
||||
|
||||
async ngOnInit(): Promise<void> {
|
||||
const premium = await this.stateService.getCanAccessPremium();
|
||||
|
||||
if (premium) {
|
||||
this.viewContainer.clear();
|
||||
} else {
|
||||
this.viewContainer.createEmbeddedView(this.templateRef);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
import { Directive, OnInit, TemplateRef, ViewContainerRef } from "@angular/core";
|
||||
|
||||
import { StateService } from "jslib-common/abstractions/state.service";
|
||||
|
||||
/**
|
||||
* Only shows the element if the user has premium.
|
||||
*/
|
||||
@Directive({
|
||||
selector: "[appPremium]",
|
||||
})
|
||||
export class PremiumDirective implements OnInit {
|
||||
constructor(
|
||||
private templateRef: TemplateRef<any>,
|
||||
private viewContainer: ViewContainerRef,
|
||||
private stateService: StateService
|
||||
) {}
|
||||
|
||||
async ngOnInit(): Promise<void> {
|
||||
const premium = await this.stateService.getCanAccessPremium();
|
||||
|
||||
if (premium) {
|
||||
this.viewContainer.createEmbeddedView(this.templateRef);
|
||||
} else {
|
||||
this.viewContainer.clear();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue