angular-ngrx-material-starter
Angular, NgRx, Angular CLI & Angular Material Starter Project
Top Related Projects
Reactive State for Angular
CLI tool for Angular
Material design for AngularJS
Customizable admin dashboard template based on Angular 10+
angular e-commerce framework for online store
Material Dashboard Angular
Quick Overview
Angular NgRx Material Starter is a comprehensive boilerplate project for Angular applications. It combines Angular, NgRx for state management, and Angular Material for UI components, providing a solid foundation for building scalable and maintainable web applications.
Pros
- Integrates popular and powerful technologies (Angular, NgRx, Material) out of the box
- Includes a wide range of features like authentication, theming, and i18n support
- Well-structured and follows best practices for Angular development
- Regularly updated and maintained
Cons
- May have a steep learning curve for developers new to Angular or NgRx
- The extensive feature set might be overwhelming for simple projects
- Opinionated structure may not fit all project requirements
- Requires understanding of multiple libraries and concepts
Code Examples
- Using NgRx store to manage state:
@Component({...})
export class TodosComponent {
todos$: Observable<Todo[]>;
constructor(private store: Store<AppState>) {
this.todos$ = this.store.select(selectAllTodos);
}
addTodo(title: string) {
this.store.dispatch(addTodo({ title }));
}
}
- Implementing a custom theme:
@NgModule({
imports: [
// ...
MatButtonModule,
MatToolbarModule,
MatSidenavModule,
],
})
export class AppModule {
constructor(private overlayContainer: OverlayContainer) {
overlayContainer.getContainerElement().classList.add('my-custom-theme');
}
}
- Using Angular Material components:
<mat-toolbar color="primary">
<button mat-icon-button (click)="sidenav.toggle()">
<mat-icon>menu</mat-icon>
</button>
<span>My App</span>
</mat-toolbar>
<mat-sidenav-container>
<mat-sidenav #sidenav mode="side">
<!-- Sidenav content -->
</mat-sidenav>
<mat-sidenav-content>
<!-- Main content -->
</mat-sidenav-content>
</mat-sidenav-container>
Getting Started
-
Clone the repository:
git clone https://github.com/tomastrajan/angular-ngrx-material-starter.git
-
Install dependencies:
cd angular-ngrx-material-starter npm install
-
Run the development server:
npm start
-
Open your browser and navigate to
http://localhost:4200
Competitor Comparisons
Reactive State for Angular
Pros of platform
- Official NgRx library, providing core state management functionality
- Extensive documentation and community support
- Regular updates and maintenance from the NgRx team
Cons of platform
- Steeper learning curve for beginners
- Requires more boilerplate code for setup
- Lacks pre-built UI components and styling
Code Comparison
angular-ngrx-material-starter:
@Effect()
login$ = this.actions$.pipe(
ofType(AuthActionTypes.LOGIN),
map((action: Login) => action.payload),
exhaustMap((auth) =>
this.authService.login(auth).pipe(
map((user) => new LoginSuccess({ user })),
catchError((error) => of(new LoginFailure({ error })))
)
)
);
platform:
login$ = createEffect(() =>
this.actions$.pipe(
ofType(login),
exhaustMap(({ username, password }) =>
this.authService.login(username, password).pipe(
map((user) => loginSuccess({ user })),
catchError((error) => of(loginFailure({ error })))
)
)
)
);
The code comparison shows that platform uses a more modern, functional approach with createEffect, while angular-ngrx-material-starter uses the older @Effect decorator. Both achieve similar results, but platform's syntax is more concise and aligned with current NgRx best practices.
CLI tool for Angular
Pros of angular-cli
- Official Angular tool for project scaffolding and development
- Extensive documentation and community support
- Regularly updated with new Angular features and best practices
Cons of angular-cli
- Less opinionated about project structure and state management
- Requires additional setup for advanced features like NgRx and Material Design
- May have a steeper learning curve for beginners
Code Comparison
angular-cli (default component):
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'my-app';
}
angular-ngrx-material-starter (example component):
import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
import { Store, select } from '@ngrx/store';
import { Observable } from 'rxjs';
import { selectIsAuthenticated } from './core/auth/auth.selectors';
@Component({
selector: 'anms-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class AppComponent implements OnInit {
isAuthenticated$: Observable<boolean>;
constructor(private store: Store) {}
ngOnInit() {
this.isAuthenticated$ = this.store.pipe(select(selectIsAuthenticated));
}
}
The angular-ngrx-material-starter example shows integration with NgRx for state management and follows more advanced Angular practices, while the angular-cli example provides a simpler starting point for basic applications.
Material design for AngularJS
Pros of Angular Material
- Official Angular component library, ensuring long-term support and compatibility
- Extensive documentation and community support
- Comprehensive set of pre-built, accessible UI components
Cons of Angular Material
- Less opinionated about application structure and state management
- Requires additional setup for features like routing and state management
- May need more customization for complex application requirements
Code Comparison
Angular Material (basic setup):
import { MatButtonModule } from '@angular/material/button';
@NgModule({
imports: [MatButtonModule],
})
export class AppModule { }
Angular-ngrx-material-starter (includes NgRx setup):
import { StoreModule } from '@ngrx/store';
import { EffectsModule } from '@ngrx/effects';
@NgModule({
imports: [
StoreModule.forRoot(reducers, { metaReducers }),
EffectsModule.forRoot([AppEffects])
],
})
export class AppModule { }
Angular Material focuses on providing UI components, while Angular-ngrx-material-starter offers a more complete application structure with state management integrated. The latter provides a more opinionated starting point for complex applications, including NgRx setup out of the box. Angular Material, being more flexible, requires developers to make additional architectural decisions but offers greater customization potential for diverse project needs.
Customizable admin dashboard template based on Angular 10+
Pros of ngx-admin
- More comprehensive UI components and pre-built pages
- Extensive theming options with multiple color schemes
- Better suited for large-scale enterprise applications
Cons of ngx-admin
- Steeper learning curve due to its complexity
- Potentially bloated with features that may not be needed
- Less focus on state management patterns like NgRx
Code Comparison
angular-ngrx-material-starter:
@NgModule({
imports: [
StoreModule.forRoot(reducers, { metaReducers }),
StoreRouterConnectingModule.forRoot(),
EffectsModule.forRoot([AuthEffects, GoogleAnalyticsEffects])
]
})
ngx-admin:
@NgModule({
imports: [
ThemeModule,
NbMenuModule.forRoot(),
NbLayoutModule,
NbEvaIconsModule
]
})
The code snippets highlight the different focus areas of each project. angular-ngrx-material-starter emphasizes state management with NgRx, while ngx-admin concentrates on UI components and theming.
angular-ngrx-material-starter is more suitable for developers who prioritize robust state management and prefer a leaner starting point. It's ideal for projects that require a solid foundation in Angular best practices and NgRx integration.
ngx-admin, on the other hand, is better for rapid prototyping of complex admin interfaces or when a wide range of pre-built UI components is needed. It's particularly useful for projects that require extensive customization options and don't necessarily need advanced state management out of the box.
angular e-commerce framework for online store
Pros of angularspree
- Focused on e-commerce functionality, providing a more specialized solution for online stores
- Includes features like product catalog, shopping cart, and order management out of the box
- Integrates with Spree Commerce backend, offering a robust and scalable e-commerce platform
Cons of angularspree
- Less frequently updated compared to angular-ngrx-material-starter
- More complex setup due to its dependency on Spree Commerce backend
- Limited customization options for non-e-commerce applications
Code Comparison
angular-ngrx-material-starter:
@NgModule({
imports: [
StoreModule.forRoot(reducers, { metaReducers }),
StoreRouterConnectingModule.forRoot(),
environment.production ? [] : StoreDevtoolsModule.instrument()
],
// ...
})
angularspree:
@NgModule({
imports: [
BrowserModule,
HttpClientModule,
HomeModule,
LayoutModule,
CoreModule,
StoreModule.forRoot(reducers, { metaReducers }),
// ...
],
// ...
})
Both projects use NgRx for state management, but angularspree includes more specific modules related to e-commerce functionality. The angular-ngrx-material-starter focuses on providing a more general-purpose starter template with Material Design integration.
Material Dashboard Angular
Pros of material-dashboard-angular2
- Offers a more comprehensive and polished dashboard UI out of the box
- Includes a wider variety of pre-built components and layouts
- Provides better documentation and examples for quick implementation
Cons of material-dashboard-angular2
- Less focus on state management (NgRx) compared to angular-ngrx-material-starter
- May require more customization for specific use cases
- Potentially steeper learning curve for developers new to Angular Material
Code Comparison
angular-ngrx-material-starter:
@NgModule({
imports: [
StoreModule.forRoot(reducers, { metaReducers }),
StoreRouterConnectingModule.forRoot(),
EffectsModule.forRoot([AuthEffects, GoogleAnalyticsEffects])
]
})
material-dashboard-angular2:
@NgModule({
imports: [
MatButtonModule,
MatRippleModule,
MatFormFieldModule,
MatInputModule,
MatSelectModule,
MatTooltipModule
]
})
The code snippets highlight the different focus areas of the two projects. angular-ngrx-material-starter emphasizes state management with NgRx, while material-dashboard-angular2 concentrates on Angular Material components for UI development.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Angular 12, NgRx and Angular Material Starter
by @tomastrajan
Table of Content
- Live Demo
- Getting Started
- Useful Commands
- Make It Your Own
- Goals
- Learning Materials
- List of Projects Built Using This Starter
- Features
- Stack
- Code of Conduct
- Contributors Guide
- Changelog ( get notified about the newest releases, follow Release Butler on Twitter )
Getting started
git clone https://github.com/tomastrajan/angular-ngrx-material-starter.git new-project
cd new-project
npm install
npm start
Useful Commands
npm start
- starts a dev server and opens browser with running appnpm run start:prod
- runs full prod build and serves prod bundlenpm run test
- runs lint and testsnpm run e2e
- runs end-to-end testsnpm run watch
- runs tests in watch modenpm run format:write
- runs prettier to format whole code base (.ts
and.scss
)npm run analyze
- runs full prod build andwebpack-bundle-analyzer
to visualize how much code is shipped (dependencies & application)
Make It Your Own
When using this starter project to build your own app you might consider some of the following steps:
- use
search and replace
functionality of your favourite IDE to replaceanms
with<your-app-prefix>
- rename project in
package.json
name
property and set appropriate version (eg0.0.0
or1.0.0
) - remove / rename context path config
-- --deploy-url /angular-ngrx-material-starter/ --base-href /angular-ngrx-material-starter
inpackage.json
, this is used to configure url (context path) on which the application will be available (eg.https://www.something.com/<context-path>/
) - rename app in
/environments/
files (will be shown in browser tab) - delete pre-existing
CHANGELOG.md
(you will generate your own with future releases of your features) - delete
CODE_OF_CONDUCT.md
,CONTRIBUTING.md
andBUILT_WITH.md
files as they are relevant only if project is open sourced on Github - edit the title and Open Graph metadata properties in
index.html
- remove or adjust links in the footer
- replace logo in
/assets
folder ( currently 128 x 128 pixelpng
file ) - adjust colors in
/themes/default-theme.scss
- create a pull request in the original repository to update
BUILT_WITH.md
file with a link and short description of your project
Continuous Integration
Starter project is using Travis CI for running linters and tests on every commit. Based on your preferences and needs you can either:
- not use / use other CI server and delete both
.travis.yml
and.travis-deploy.sh
- create Travis CI account and link it to your projects Github repo and configure build
with
GH_REF
andGH_TOKEN
environment variables for automatic deployment of releases to Github Pages
Goals
The main goal of this repository is to provide an up to date example of Angular application following all recent best practices in various areas like:
@ngrx/store
- including reducers, actions, selectors@ngrx/effects
- for implementation of side effects likehttp
requests, logging, notifications,...@ngrx/entity
- for CRUD operations@ngrx/router-store
- to connect the Angular Router to @ngrx/store@ngrx/store-devtools
- to enable a powerful time-travelling debugger.@angular/material
- material design component library, theming, ...- routing
- testing of all the above mentioned concepts
- Angular CLI configuration (prod build, budgets, ...)
This repository will also strive to always stay in sync with releases of Angular and the related libraries. The nature of the repository is also a great match for first time open source contributors who can add simple features and enhance test coverage, all contributors are more than welcome!
Learning Materials
Articles with content that explains various approaches used to build this starter project.
- Blog post about Best subscribing to RxJS Observable data by Components: subscribe() vs | async pipe
- Blog post about Best Practices for Angular CLI used in this starter project
- Blog post about Typescript tips for Ngrx reducer code
- Blog post about building responsive layouts with Bootstrap 4 in Angular apps
- Blog post about configuration of animations during runtime
- Blog post about unit testing of components with NgRx TestStore
- Blog post about Angular CLI budgets
- Blog post about the best way to unsubscribe RxJs streams
- Blog post about Angular 6+ DI with providedIn
- Blog post about the best way to lazy load Angular Elements
Theming
Features
- custom themes support (4 themes included)
- lazy-loading of feature modules
- lazy reducers
- localStorage ui state persistence
@ngrx/effects
for API requests- fully responsive design
- angular-material and custom components in
SharedModule
Stack
- Angular
- ngrx (or try ngx-model if you prefer less boilerplate)
- Angular Material
- Bootstrap 5 (only reset, utils and grids)
Troubleshooting
- Blocking at emitting LicenseWebpackPlugin when npm start - try using cnpm instead of npm
Contributors
Want to start contributing to open source with Angular?
Leave your mark and join the growing team of contributors!
Get started by checking out list of open issues and reading Contributor Guide
Top Related Projects
Reactive State for Angular
CLI tool for Angular
Material design for AngularJS
Customizable admin dashboard template based on Angular 10+
angular e-commerce framework for online store
Material Dashboard Angular
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot