ngx-admin-lte
Admin-LTE for Angular 4/5/6 as a NPM package
This project is a library to integrate in your own project. If your are looking for a full bootstrapping using this library, please check: Bootstrapping Ngx-Admin-Lte
Documentation
Documentation is available here Documentation
Support & Contribution
This project is maintained on personnal time.
As so weI can't assure you that all questions/issues will be answered as quickly as you need.
But the communauty around it is growing fast, more than 200 projects are using it
And it's an open-source project, so feel free to add feature / fix issues via Pull Requests (they will be merged quickly).
Furthermore, if you like this project and you do want to help us, please considere donating.
Every little help is welcome :)
Installation
This lib is only tested on angular-cli projects, but it may work in any angular project.
Install this lib in your existing project with
yarn add ngx-admin-lte
or npm install ngx-admin-lte
in your app.modules.ts, add these statements:
; @
Add js and css of admin-lte in your project like so:
in your angular-cli.json
"assets": , "scripts": ,
in your style.css
;;;;;;
then you can declare your component with the adminLte template in your router:
; ... const routes: Routes = // logged routes canActivate: CanActivateGuard children: canActivate: CanActivateGuard component: HomeComponent path: 'home' canActivate: CanActivateGuard component: PageNumComponent path: 'page/:id' component: LayoutAuthComponent path: '' // not logged routes component: LayoutLoginComponent path: 'login' component: RegisterComponent path: 'register' ;
Handling Translation
In order to use the translation files given by the libraries, you should configure your angular-cli as:
But if you want to provide your own translation files, lets say in a folder named "src/public/i18n" in your project.
( That you could have initialised it by doing cp -r ./node_modules/ngx-admin-lte/src/public/assets/i18n ./src/public/
in your project)
You could do that like so:
,
Same principle applies if you want to override the "img" assets folder
Configuration
You can change skin and hide some buttons by passing data to the layout component like so:
component: LayoutAuthComponent data: 'skin': 'skin-black' /* // USE THIS IS YOU WANT TO HIDE SOME TEMPLATE PART 'boxed_style': false, 'display_tasks': false, 'display_control': false, 'display_user': false, 'display_messages': false, 'display_notifications': false, 'display_menu_user': false, 'display_menu_search': false, 'display_logout': true, 'display_control_sidebar': true, header_components: [] */
DEPRECATED: Please don't use 'menu_title' anymore, you can just set 'header' property in your links setting.
Don't forget to import the css skin in you style.css if you use it.
Additionnal components
You can add some components in the header by adding some in the configuration of the layout like so:
'header_components': [{
class: MenuWidgetComponent,
data: {
label: 'test widget'
}
}]
the same structure can be used in the menu configuration to add components in the left menu.
import { MenuWidgetComponent } from './widgets/menu-widget/menu-widget.component';
...
let mylinks = [
//some standard link ...
{
'title': 'External Links',
'icon': 'link',
'sublinks': [
{
'title': 'Github',
'link': ['https://github.com/TwanoO67/ngx-admin-lte'],
'icon': 'github',
'external': true,
'target': '_blank'
}
]
},
// and an additionnal component
{
class: MenuWidgetComponent,
data: {
label: 'test component'
}
}
];
// then define the menu
this.menuService.setCurrent(this.mylinks);
Don't forget to add your component to the declarations and entryComponents part of your module file. Those components must implement OnChanges (so they can receive data)
Services
If you need some practical example of using this services, check out the project Bootstraping-ngx-admin-lte
BreadcrumbService
Helper to set the breadcrumb in a LayoutAuthComponent extended page.
Example for an homepage:
{ public { // settings the header for the home thisbreadServ; } public { // removing the header thisbreadServclear; }
CanActivateGuard
Service that check if the user is connected. If you want to use it, just put in you routes like, so;
; // ... component: MyComponent canActivate: CanActivateGuard path: 'mycompo'
And set a user.connected = true
in your user service.
Example of a basic login page:
{ private { // DOING SOME BACKOFFICE STUFF ON THE SERVER // then if the server said OK, then log the user in js if 1 === 1 const user1 = avatarUrl: 'assets/img/user2-160x160.jpg' email: 'weber.antoine@outlook.com' firstname: 'WEBER' lastname: 'Antoine' ; user1connected = true; thisuserServ; thisrouter; }
FooterService
Helper to define the footer of an LayoutAuthComponent extended page.
use setCurrent to send your footer with { left_part: "some text or", right_part: "some <span>html</span>"}
LoggerService
the method log is used to show some console.log using the i18n translation
LogoService
Helper to define the logo of an LayoutAuthComponent extended page.
use setCurrent to send your logo with { html_mini; "<b>A</b>LTE", html_lg; "<b>Admin</b>LTE", }
You can define your own brand name in the logo, if you want it to be initialised once, do it in your app.compontent.ts like so:
; { // ... thislogoServ;
Please remove any usage of it.
MenuService
You can set the menu links, globally (if you do that in your app.component.ts for example), or locally, if you do that in each of your component.
; // ... // define here your own links menu structureprivate mylinks: any = 'header': 'Custom Header' 'title': 'Home' 'icon': 'dashboard' 'link': '/' 'title': 'Sub menu' 'icon': 'link' 'sublinks': 'title': 'Page 2' 'link': '/page/2' 'title': 'Page 3' 'link': '/page/3' ; { } public { // define menu thismenuServ;
MessagesService
Can be used to send message in the message box of the header
Example:
{ // ... } public { // FAKE MESSAGE // defining some users const user1 = avatarUrl: 'assets/img/user2-160x160.jpg' email: 'weber.antoine.pro@gmail.com' firstname: 'WEBER' lastname: 'Antoine' ; const user2 = avatarUrl: 'assets/img/user2-160x160.jpg' email: 'EMAIL' firstname: 'FIRSTNAME' lastname: 'LASTNAME' ; // sending a test message thismsgServ;
NotificationsService
Can be used to send notification in the notification box of the header
Example:
{ ... } public { // sending a test notification thisnotifServ;
RestService
Abstract service to contact a REST API. You can use that to do Services for you data models.
Example, for a model named "Device"
;;;;; @ { super_http; thismodelName = 'devices'; this; } /*This parts are only needed if you want to have correct types for your datas*/ public : Observable<Device> return super; public : Observable<Device> return super;
This service will now provide base CRUD functionality respecting the RESP in JSON API format.
// CONFIGURATION // HELPERS WITH CACHE: Array<any>: any // Standard REST functions: Observable<any>: Observable<any>: Observable<number>: Observable<Array<number>>: Observable<number>deleteid: number: Observable<Response>
TranslateService
This service will listen to your user changes and check if the current user has a selected language (in the field preferredLang
).
If so, it will change the language of the app, accordingly.
Use the UserService to change the user, with language set like so:
avatarUrl: 'assets/img/user2-160x160.jpg' email: 'weber.antoine@outlook.com' firstname: 'WEBER' lastname: 'Antoine' //set the language here preferredLang: 'fr' ;
Supported language are: 'en', 'fr', 'ru', 'he', 'zh'
If no preferredLang is given, it will take the browser settings, and otherwise default is 'en'.
User service
This service is used to send/get the current user information across the app
For example you can set the current user, in your login page :
; { { let user = firstname: "WEBER" lastname: "Antoine" email: "why-not-yop@yopmail.com" avatarUrl: "assets/img/user2-160x160.jpg" ; this_user_serv;
and you can get the user in a widget:
; private current_user: User;{ //se connecter au modification du user courant this_user_servcurrent_user;
Specific Components
App Header
This widget handles the header bar, it includes other 'box' widgets for the top navigation:
- Messages Box
- Notification Box
- Tasks Box
- User box
Messages Box
This widget is registered to the messages service
Notification Box
WIP This widget is registered to the notification service
Tasks Box
WIP This widget is registered to the task service
User box
This widget is registered to the user service (for the current user display)
Menu Aside
This widget handles the left navigation Menu It is registered to the user service (for the current user display)
Models
User
- firstname: string, First Name of the user
- lastname : string, Last Name of the user
- email : string, Email address of the user
- avatarUrl : string, URL for the user avatar, could be absolute or relative
- creation_date : string, timestamp of the creation of the user
Message
- title : string, title of the message
- content : string, content of the message
- author : User, source user of the message
- destination : User, destination user of the message
- date : string, date of sending