GithubHelp home page GithubHelp logo

dubangarcia / ngx-loadable Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mohammedzamakhan/ngx-loadable

0.0 1.0 0.0 1.29 MB

⏳ Simple Lazy Loading for Non Routable Angular Modules

Home Page: https://mohammedzamakhan.github.io/ngx-loadable/

License: MIT License

JavaScript 7.04% TypeScript 50.18% CSS 1.30% HTML 41.48%

ngx-loadable's Introduction

ngx-loadable

license

ngx-loadable logo The library logo represents faster application like speed of wind

Table of Contents

Problem

Angular provides an easy way for adding route based lazy loading modules. But in most of the projects, each route tends to have a lot of different components. It could be because of lots of modals, tabs, and components that appear based on user interaction in a single route.

Solution

The ngx-loadable wraps the complex implementation for lazy loading non routable modules in a simple API. It provides a component ngx-loadable and a service LoadableService to lazy load modules. A component can be used to control the loading of one module and to display different states, i.e. loading, error, timedOut and loaded.

Install

Install and manage the ngx-loadable using NPM. You may use yarn or npm.

npm install ngx-loadable --save

or

yarn add ngx-loadable

Usage

NgModule

Import the LoadableModule in the NgModule and declare them in the "imports", you can also use the forRoot() for forChild() function.

  • Step 1:
import { LoadableModule } from 'ngx-loadable';

@NgModule({
  imports: [
    LoadableModule
  ]
})
  • Step 2: Create a Module with a Component bootstrapped to the Module

  • Step 3: Include the module path in the lazyModules array in angular.json file, for it to be created as a lazy module by Angular CLI

  • Step 4: Use the ngx-loadable component

<button (click)="show = true" (mouseenter)="loginModalModule.preload()">
    Preload on mouseenter and show on click
</button>
<ngx-loadable
    #loginModalModule
    [module]="'login-modal'"
    [show]="show"
    [timeout]="1000"
>
    <div loading>Loading...</div>
    <div error>Error</div>
    <div timedOut>
        TimedOut!
        <button (click)="loginModalModule.reload()">
            Reload
        </button>
    </div>
</ngx-loadable>

or use the LoadableService

import { LoadableService } from 'ngx-loadable';
...
class YourComponent {
    contructor(private loadableService: LoadableService) { }
    load() {
        this.loadableService.preload('lazy')
            .then(() => console.log('loaded'))
            .catch((error) => console.error(error));
        }
    }
}

Contribute

Please contribute by creating issues/PRs

License

© 2019 ngx-loadable. All Rights Reserved.

ngx-loadable's People

Contributors

mohammedzamakhan avatar

Watchers

James Cloos 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.