Showing posts with label angular 2/4. Show all posts
Showing posts with label angular 2/4. Show all posts


September 22, 2018
Native Angular directives for Bootstrap


Table of contents

  1. Getting Started
  2. Installation instructions
  3. Usage & Demo
  4. API
  5. Troubleshooting
  6. Contributing
  7. License

Getting Started

ngx-bootstrap contains all core (and not only) Bootstrap components powered by Angular. So you don't need to include original JS components, but we are using markup and css provided by Bootstrap.

Installation instructions

Install ngx-bootstrap from npm
 npm install ngx-bootstrap --save
You will need bootstrap styles (Bootstrap 3)

Or Bootstrap 4

To enable bootstrap 4 theme templates in ngx-bootstrap, please read this.

Usage & Demo

Main source of API documentation and usage scenarios available here:
Additionally you can find demos and docs deployed from latest code with angular v4 and angular v5
Server side rendered version of this documentation available here


Check demo page for API reference

How to use it with:

How to build lib for development

First time
  • clone repository
  • npm install
  • npm run test it will build the lib and create a link in node_modules
To run bootstrap 3 and 4 demo:
  • npm run demo.serve to serve local demo. This is for testing only, without watchers.
For local development run
  • npm run in first terminal
  • ng serve in second
If you want to run the demo with Angular Universal:
  • npm run demo.serve-universal


So if you are in trouble, here's where you can look for help.
The best place to ask questions is on StackOverflow (under the ngx-bootstrap tag) You can also join our Slack channel and link your stackoverflow question there. But try to avoid asking generic help questions directly on Slack since they can easily get lost in the chat. You can also search among the existing GitHub issues.
If, and only if, none of the above helped, please open a new issue.

Note: Special thanks to Valor Software
Disclaimer: The blog is created to share angular directives information to geek, curious Angular Developers.


September 11, 2018
Angular2 Directive For React Component


After 0.3.0 or higher, ng2-react has been changed to @ngui/react. Here are the changes;
  • Module ng2-react is changed to @ngui/react
  • Direvtive ng2-react is changed to ngui-react
  • Class name Ng2React is changed to NguiReact

With @ngui/react, we can do the following from Angular2

  • Pass read-only props to React component
  • Call a function in React component
  • Fire event in React componet
  • Set state of React componet
You need more? Please log a feature requirement

How Does It Work

  1. Angular renders ngui-react component with the following attributes;
  • reactComponent, A React component to render. Let's call it as MyComp.
  • reactProps, react props for the React component, MyComp.
  • reactState, the initial state to be used by MyComp
  1. ngui-react create and render React component using;
  • React.createElement()
  • React.render()

Access ReactJS properties

You can access react element and instance from Angular component.
  • reactElement: the react element from React.createElement()
  • reactInstance: the react instance from React.render()


  1. install @ngui/react
     $ npm install @ngui/react --save  
  2. import NguiReactModule to your AppModule
  3.  import { NgModule } from '@angular/core';  
      import { FormsModule } from "@angular/forms";  
      import { BrowserModule } from '@angular/platform-browser';  
      import { AppComponent } from './app.component';  
      import { NguiReactModule } from '@ngui/react';  
       imports: [BrowserModule, FormsModule, NguiReactModule],  
       declarations: [AppComponent],  
       bootstrap: [ AppComponent ]  
      export class AppModule { }  
For full example, please check out app directory to see the example of
  • app.module.ts
  • and app.component.ts

Example Usage


 class Hello extends React.Component {  
  render() {  
   return <div>Hello {}</div>;  


 import { Component, ViewChild } from '@angular/core';  
 import { Hello } from "./hello"; // This is a react component  
  selector: 'my-app',  
  template: `  
    [reactProps]="{name:'angular2 react wrapper'}">  

Note: Special thanks to ng2-ui


Disclaimer: The blog is created to share angular directives information to geek, curious Angular Developers.


July 05, 2018
:telephone_receiver: Microservice framework for RabbitMQ written in TypeScript


coconspirators is a microservice framework for RabbitMQ written in TypeScript. Under the hood it uses qmqp.node, the battle-tested AMQP client, to communicate with RabbitMQ and has best-practices baked in. Features include:
  • Simple API for subscribing, publish and replying
  • DI Friendly
  • TypeScript First



 npm i coconspirators --S  


 npm run build  


 import { Queue, AmqpQueue, AmqpClient } from 'coconspirators';  
 export class AmqpServer {  
  connection: Promise<any>;  
  constructor(public client: AmqpClient, logger: Logger) {  
   this.connection = this.client.connect();  
   client.on('connected', () => console.log('connected!'));  
   client.on('disconnected', () => console.log('disconnected!'));  
 interface ZooMessage {  
  animal: string;  
  name: 'health'  
  contentType: 'application/json'  
 export class HealthQueue extends AmqpQueue<ZooMessage> {  
  constructor(client: AmqpClient) { super(client); }  
 export class HealthChecker {  
  constructor(queue: HealthQueue) {  
   this.queue.publish({ hi: true });  
   this.queue.subscribe((message: ZooMessage) => {  
    console.log('message', message);  


ngx-datatable is a Swimlane open-source project; we believe in giving back to the open-source community by sharing some of the projects we build for our application. Swimlane is an automated cyber security operations and incident response platform that enables cyber security teams to leverage threat intelligence, speed up incident response and automate security operations.

Note: Special thanks to Swimlane


Disclaimer: The blog is created to share angular directives information to geek, curious Angular Developers.


June 27, 2018

Web Notifications Powered by RxJS for Angular 2

Easily create and handle desktop notifications in Angular 2


Install @ngrx/notify from npm:

npm install @ngrx/notify --save

Setup the providers, optionally providing global notification options:

import { NOTIFY_PROVIDERS, NOTIFY_GLOBAL_OPTIONS } from '@ngrx/notify';

bootstrap(App, [
  { provide: NOTIFY_GLOBAL_OPTIONS, multi: true, useValue: { /* global options here */ } }


Requesting Notification Permission

Before creating notifications, you must resolve the app's notification permission:
class AppComponent {
  constructor(notify: Notify) {
    notify.requestPermission().subscribe(permission => {
      if (permission) {
        // continue

Creating a Notification

To create a notification observable, call the open() method with a title and optional config. The notification will be opened when you subscribe to the observable and will close after you unsubscribe from it. The observable will emit the instance of the notification every time it is clicked on:'Hello world!', options)
  // Automatically close the notification after 5 seconds
  // Close the notification after it has been clicked once
  .subscribe(notification => {


See the documentation on MDN for available options.



June 09, 2018

ngx-modialog (previously `angular2-modal`)

This project is looking for a new maintainer, see [#414]( for details.

ngx-modialog version 5.x.x works with angular 5.x.x


Version 4.x.x contains some breaking changes, please see the [CHANGELOG](./

Library has been renamed from version 3.0.2

Modal / Dialog implementation for angular. - Easy to use API via Fluent API Presets (alert, prompt, confirm) - Can render Component's, TemplateRef's and literal string - Extendable via plugins. - Easy to use typescript modal.alert() .title('Hello World') .body('In Angular') .open(); Available plugins: - Bootstrap (3 & 4) - [Vex 3 & 4](


bash npm install ngx-modialog

Basic plunker playground (bootstrap plugin):

ngx-modialog @ 4.x.x

ngx-modialog @ 3.x.x

Quick start

**In your application root module definition add `ModalModule` and the plugin you want to use:** We will use the bootstrap plugin (`BootstrapModalModule`) for this introduction. ```typescript import { ModalModule } from 'ngx-modialog'; import { BootstrapModalModule } from 'ngx-modialog/plugins/bootstrap'; // lots of code... @NgModule({ bootstrap: [ /* ... */ ], declarations: [ /* ... */ ], imports: [ /* ... */ ModalModule.forRoot(), BootstrapModalModule ], }) export class AppModule { /* lots of code... */ } ```

In any angular component or service inject the `Modal` service and open a modal:

typescript import { Component, ViewContainerRef } from '@angular/core'; import { Overlay } from 'ngx-modialog'; import { Modal } from 'ngx-modialog/plugins/bootstrap'; @Component({ selector: 'my-app', template: `<button (click)="onClick()">Alert</button>` }) export class AppComponent { constructor(public modal: Modal) { } onClick() { const dialogRef = this.modal.alert() .size('lg') .showClose(true) .title('A simple Alert style modal window') .body(` <h4>Alert is a classic (title/body/footer) 1 button modal window that does not block.</h4> <b>Configuration:</b> <ul> <li>Non blocking (click anywhere outside to dismiss)</li> <li>Size large</li> <li>Dismissed with default keyboard key (ESC)</li> <li>Close wth button click</li> <li>HTML content</li> </ul>`) .open(); dialogRef.result .then( result => alert(`The result is: ${result}`) ); } } If you are using **ngx-modialog** version 3.X.X or below, `open()` returned a promise so replace the last 2 lines with: typescript dialogRef .then( dialogRef => { dialogRef.result.then( result => alert(`The result is: ${result}`); }); We are using the `alert()` method, one of 3 (prompt, confirm)) fluent-api methods we call `drop-ins` We then use the `result` property to wait for the modal closing event. **Notes:** - Fluent API methods (drop-ins) are pre-configured (presets) methods that allow easy configuration and execution, you can create custom presets - see the demo application. - For more control use the `open()` method, which is used by all drop in's internally. - We import the `Modal` service from the plugin and not from the root library. Import from the root should work but being explicit allow using multiple plugins. ## Demo App The Demo application is a full implementation of the library with the native plugins. View it at []( The demo application is [part of this repository]( and it is a great place to learn by example.

Bootstrap / VEX features:

- Customizable with components, Presets and more... - Select cancel/quit key. - Cascading modals. - Element blocking. - Blocking / Non blocking modal. - Modal as a component, replace the content by supplying a custom component. The demo application comes with a [dynamic modal generator]( for the **Boostrap** plugin ## Plugins Plugins serve as a concrete UI implementation for a modal. It can be an implementation for a known library (e.g: bootstrap) or something completely unique While `ngx-modialog` has some built in plugins it is also possible to use external plugins from NPM, if someone decide to build one. > Built a plugin? I would love to know :) # Known bugs ### The dialog closes when removing the target DOM element in a click event ref [issue#111]( To avoid this problem use `event.stopPropagation();` or put the element removal inside a `setTimeout` call # HELP WANTED! As a sole author I find it difficult to maintain multiple open source projects. As a result it is hard for me to replay rapidly to requests/help/etc... If you would like to contribute, please contact me, the community will thank you. You can contribute via: - Implementing features & Bug fixes - Documentation (Extremely important) - Issue management


February 02, 2018
The idea is simple: Add a loading bar / progress bar whenever an XHR request goes out in angular. Multiple requests within the same time period get bundled together such that each response increments the progress bar by the appropriate amount.
This is mostly cool because you simply include it in your app, and it works. There's no complicated setup, and no need to maintain the state of the loading bar; it's all handled automatically by the interceptor.

Requirements: AngularJS 1.2+

File Size: 2.4Kb minified, 0.5Kb gzipped


  1. include the loading bar as a dependency for your app. If you want animations, include ngAnimate as well. note: ngAnimate is optional
     angular.module('myApp', ['angular-loading-bar', 'ngAnimate'])  
  2. include the supplied JS and CSS file (or create your own CSS to override defaults).
     <link rel='stylesheet' href='build/loading-bar.min.css' type='text/css' media='all' />  
     <script type='text/javascript' src='build/loading-bar.min.js'></script>  
  3. That's it -- you're done!

via bower:

 $ bower install angular-loading-bar  

via npm:

 $ npm install angular-loading-bar  

via CDN:

  <link rel='stylesheet' href='//' type='text/css' media='all' />  
  <script type='text/javascript' src='//'></script>  

Why I created this

There are a couple projects similar to this out there, but none were ideal for me. All implementations I've seen require that you maintain state on behalf of the loading bar. In other words, you're setting the value of the loading/progress bar manually from potentially many different locations. This becomes complicated when you have a very large application with several services all making independent XHR requests. It becomes even more complicated if you want these services to be loosly coupled.
Additionally, Angular was created as a highly testable framework, so it pains me to see Angular modules without tests. That is not the case here as this loading bar ships with 100% code coverage.
Goals for this project:
  1. Make it automatic
  2. Unit tests, 100% coverage
  3. Must work well with ngAnimate
  4. Must be styled via external CSS (not inline)
  5. No jQuery dependencies


Turn the spinner on or off:

The insertion of the spinner can be controlled through configuration. It's on by default, but if you'd like to turn it off, simply configure the service:
 angular.module('myApp', ['angular-loading-bar'])  
  .config(['cfpLoadingBarProvider', function(cfpLoadingBarProvider) {  
   cfpLoadingBarProvider.includeSpinner = false;  

Turn the loading bar on or off:

Like the spinner configuration above, the loading bar can also be turned off for cases where you only want the spinner:
 angular.module('myApp', ['angular-loading-bar'])  
  .config(['cfpLoadingBarProvider', function(cfpLoadingBarProvider) {  
   cfpLoadingBarProvider.includeBar = false;  

Customize the template:

If you'd like to replace the default HTML template you can configure it by providing inline HTML as a string:
 angular.module('myApp', ['angular-loading-bar'])  
  .config(['cfpLoadingBarProvider', function(cfpLoadingBarProvider) {  
   cfpLoadingBarProvider.spinnerTemplate = '<div><span class="fa fa-spinner">Loading...</div>';  

Position the template:

If you'd like to position the loadingBar or spinner, provide a CSS selector to the element you'd like the template injected into. The default is the

 angular.module('myApp', ['angular-loading-bar'])  
  .config(['cfpLoadingBarProvider', function(cfpLoadingBarProvider) {  
   cfpLoadingBarProvider.parentSelector = '#loading-bar-container';  
   cfpLoadingBarProvider.spinnerTemplate = '<div><span class="fa fa-spinner">Custom Loading Message...</div>';  

 <div id="loading-bar-container"></div>  
Also keep in mind you'll likely want to change the CSS to reflect it's new position, so you'll need to override the default CSS:
 #loading-bar .bar {  
  position: relative;  

Latency Threshold

By default, the loading bar will only display after it has been waiting for a response for over 100ms. This helps keep things feeling snappy, and avoids the annoyingness of showing a loading bar every few seconds on really chatty applications. This threshold is totally configurable:
 angular.module('myApp', ['angular-loading-bar'])  
  .config(['cfpLoadingBarProvider', function(cfpLoadingBarProvider) {  
   cfpLoadingBarProvider.latencyThreshold = 500;  

Ignoring particular XHR requests:

The loading bar can also be forced to ignore certain requests, for example, when long-polling or periodically sending debugging information back to the server.
 // ignore a particular $http GET:  
 $http.get('/status', {  
  ignoreLoadingBar: true  
 // ignore a particular $http POST. Note: POST and GET have different  
 // method signatures:  
 $'/save', data, {  
  ignoreLoadingBar: true  

 // ignore particular $resource requests:  
 .factory('Restaurant', function($resource) {  
  return $resource('/api/restaurant/:id', {id: '@id'}, {  
   query: {  
    method: 'GET',  
    isArray: true,  
    ignoreLoadingBar: true  

How it works:

This library is split into two modules, an $http interceptor, and a service:

The interceptor simply listens for all outgoing XHR requests, and then instructs the loadingBar service to start, stop, and increment accordingly. There is no public API for the interceptor. It can be used stand-alone by including cfp.loadingBarInterceptor as a dependency for your module.

The service is responsible for the presentation of the loading bar. It injects the loading bar into the DOM, adjusts the width whenever set() is called, and complete()s the whole show by removing the loading bar from the DOM.

Service API (advanced usage)

Under normal circumstances you won't need to use this. However, if you wish to use the loading bar without the interceptor, you can do that as well. Simply include the loading bar service as a dependency instead of the main angular-loading-bar module:

 angular.module('myApp', ['cfp.loadingBar'])  

 // will insert the loading bar into the DOM, and display its progress at 1%.  
 // It will automatically call `inc()` repeatedly to give the illusion that the page load is progressing.;  
 // increments the loading bar by a random amount.  
 // It is important to note that the auto incrementing will begin to slow down as  
 // the progress increases. This is to prevent the loading bar from appearing  
 // completed (or almost complete) before the XHR request has responded.  
 cfpLoadingBar.set(0.3) // Set the loading bar to 30%  
 cfpLoadingBar.status() // Returns the loading bar's progress.  
 // -> 0.3  
 // Set the loading bar's progress to 100%, and then remove it from the DOM.  


The loading bar broadcasts the following events over $rootScope allowing further customization:

cfpLoadingBar:loading triggered upon each XHR request that is not already cached

cfpLoadingBar:loaded triggered each time an XHR request recieves a response (either successful or error)

cfpLoadingBar:started triggered once upon the first XHR request. Will trigger again if another request goes out after cfpLoadingBar:completed has triggered.

cfpLoadingBar:completed triggered once when the all XHR requests have returned (either successfully or not)


Credit goes to rstacruz for his excellent nProgress.

Note: Special thanks to Wes Cruver
Disclaimer: The blog is created to share angular directives information to geek, curious Angular Developers.