Socket
Socket
Sign inDemoInstall

ngx-send-templates

Package Overview
Dependencies
5
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ngx-send-templates

Small Angular library to easily send templates to different locations.


Version published
Maintainers
1
Install size
138 kB
Created

Readme

Source

npm version

ngx-send-templates

Small Angular library to easily send templates to different locations.

Installation

Install via npm install ngx-send-templates --save and import NgxSendTemplatesModule in your AppModule.

Usage

You can now use the directives *sendTemplate and *receiveTemplate or manually use the SendTemplatesService.

Sending a template

<div *sendTemplate>Send this to the default location</div>
<div *sendTemplate="'leftNav'">Send this div to the left nav!</div>

Receive a template

<ng-container *receiveTemplate></ng-container> <!-- uses default stream -->
<p *receiveTemplate="'leftNav'">This is a placeholder while there is no template!</p>

Templates are sent via BehaviourSubjects so you will always receive the latest template.

Manage Timings

*sendTemplate

The *sendTemplate directive takes an observable as input with sendOn. Every time the observable emits, the template wil be sent.

Furthermore you can apply a pipe to change the observable behaviour.

<div *sendTemplate="'leftNav'; sendOn: button$; pipe: delayBy(5000)">This will be sent 5s after the button was clicked.</div>
<button (click)="button$.next()">Send Template</button>
button$ = new Subject<void>();

delayBy = (by: number) => (source$) => source$.pipe(
  delay(by)
);

*receiveTemplate

The *receiveTemplate directive also takes a pipe input, to change the behaviour on the receiving end.

<div *receiveTemplate="'confirm'; pipe: confirmTemplate">Placeholder ...</div>
confirmTemplate = (source$) => source$.pipe(
  map(val => confirm("Do you really want to show this?") ? val : undefined)
)

Examples

Check out the docs for use cases and code examples.

Keywords

FAQs

Last updated on 18 Jun 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc