Git Product home page Git Product logo

angular2-simple-notify's Introduction

#Angular2 Simple Notify

Intall

npm install --save angular2-simple-notify

don't forget to add systemjs config

//...
    map: {
        //...
        'angular2-simple-notify': 'node_modules/angular2-simple-notify'
    }
//...

Getting Started

import {Component} from 'angular2/core';
//...
import {NotifyComponent} from "angular2-simple-notify/notifyComponent";
import {NotifyService} from "./shared/notify/notifyService";

@Component({
    selector: 'app',
    //...
    template: `
<notify></notify>
<button (click)="onClick()">Notify</button>
    `,
    directives: [NotifyComponent]
})
export class AppComponent {
    onClick() {
        NotifyService.addNotify({name: "Notify", content:"This is a notification.", type: "danger"});
        NotifyService.addNotify({name: "Notify", content:"This is another <b>notification</b>.", timeout:1500});
    }
}

Use <notify></notify> tag only once in your application.

You can add an instant notification with NotifyService.addNotify()

Guide

NotifyInterface
{
    name: string
    content: string
    active?: boolean
    timeout?: number
    type?: string
}
NotifyComponent
<notify
        [position]="position"
        [timeout]="timeout"
        [type]="type">
</notify>
  • position: string This is the position of the notification. Default value is "top right".
  • timeout: number This is the life time of the notification. Default value is 3000.
  • type: string This is the default type of the notification. Default value is "success". Remember each notification has is own property type.
NotifyService
  • addNotify(notify: NotifyInterface): void: Add instant notification.
  • addPendingNotify(notify: NotifyInterface): void: Add notification but will be displayed after route changes.
Extends

Extends the NotifyComponent to use your own template.

Here is the minimal code before overriding the template.

import {Component} from 'angular2/core';
import {NotifyComponent} from "angular2-simple-notify/notifyComponent";

@Component({
    selector: 'my-notify',
    template: `
<div [ngStyle]="_getStyle()">
    <div
        *ngFor="#n of notify"
        [hidden]="!n.active"
        [innerHtml]="n.content">
    </div>
</div>
`
})
export class TestComponent extends NotifyComponent {
    constructor(protected _router: Router) {
        super(this._router);
    }
}

Now you just need to call <my-notify></my-notify>

angular2-simple-notify's People

Contributors

vincent-chapron avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.