-
-
Save lasfrancisco/a5ee233f17fd8a68163bdb070526a679 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Directive({ | |
selector: '[wmActionLink]' | |
}) | |
export class ActionLinkDirective implements OnDestroy { | |
private sub: Subscription; | |
constructor(private observer: ActionLinkObserver) { } | |
/** Sets the link path the directive will activate upon */ | |
@Input() set wmActionLink(link: string) { | |
// Unsubscribes previous subscriptions, if any | |
this.sub && this.sub.unsubscribe(); | |
// Registers to the specified link to emit on activation | |
this.sub = this.observer.register(link).subscribe( params => | |
this.activate.emit( params ) | |
); | |
} | |
/** Emits on activation */ | |
@Output() activate = new EventEmitter<{ [key: string]: string } | undefined>(); | |
/** Disposes of the subscriptions */ | |
ngOnDestroy() { | |
this.sub && this.sub.unsubscribe(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment