How I Would Start A New Angular Project

How I Would Start A New Angular Project
Angular: A good choice for large-scale enterprise
applications
How I Would Start A New
Angular Project
Munich Frontend Developers Meetup
21.11.2019
Hi, I‘m Michael Hoffmann
Angular CLI
We can do better…
Agenda
Nx (Monorepo)
Domain Driven Design (DDD)
OnPush
Useful Tools & Tips
Nx from Nrwl for Monorepos
DEVELOP LIKE
Not just for BIG projects
MONOREPO? WHY?
One Repo
Nx Libs & Apps
/LIBS /APPS
TypeScript
models
UI component
library
NestJS backend
Angular frontend
React frontend
Basic Nx Fullstack Workspace
Monorepos are slow
Build & Test Changesnpm run dep-graph npm run dep-graph
Run only changed code
BENEFITS OF USING NX
• Build Full-Stack Applications
• Develop like Google
• Seamlessly use modern tools like Prettier, Cypress, Jest, Nest
Domain Driven Design (DDD)
How I Would Start A New Angular Project
BENEFITS OF USING DDD
• Scalable architecture
• Ubiquitous Language
• Better code with less duplication
• And more…
Reading
Recommendation
Free eBook from
Manfred Steyer:
https://leanpub.com/en
terprise-angular
Tracker Domain
ErrorHandler, GoogleAnalytics, LoggerService
Sentry: Error Tracking
LoggerService
Global Error Handler Service
BENEFITS OF USING TRACKER DOMAIN
• Be able to see errors before the user reports them
• Be able to analzye how an error happened
How I Would Start A New Angular Project
Jest vs. Karma/jasmine
Why not Karma/jasmine?
• Slow build times (especially initially)
• Slow test execution (especially in larger projects)
• Recompiling does not work reliably
• HTML reporter like karma-jasmine-html-reporter tend to be buggy
Why Jest?
• Easy setup (especially using Nx)
• Very fast (parallelization, run slowest tests first)
• Similar syntax as jasmine
• Good mocking support
• Provides snapshot testing
Test Tips
• Consider using Spectator instead of the TestBed API of Angular.
• Consider using Jest instead of Karma/Jasmine (Migration is quite easy)
• Consider using ng-mocks to mock your component, directives, services,
pipes and more. Your unit tests should be pure and therefore isolated.
• Test your component from the DOM and not the class, you should think
in user events instead of methods.
Cypress vs. Protractor
Cypress vs. Protractor
Cypress
• Not based on Selenium
• executes in the browser and in
the same run loop as the
device under test
• No cross-browser testing
• Can only be written in JS
• no cross-browser support
Protractor
• Based on Selenium which
• is the industry standard
• works across OS & programming
languages
• supports Cross-browser testing
(even IE)
• Main problem: timing
BENEFITS OF USING BETTER TESTING TOOLS
• Writing tests makes more fun
• Code is more readable
• Tests run faster
OnPush
Why OnPush? PERFORMANCE!
CD
CD
CD CD
CD
CD CD
ChangeDetectionStrategy. Default
CD
CD
CD CD
CD
CD CD
(EVENT)
ChangeDetectionStrategy. Default
CD
CD
CD
CD
CD CD CD
ChangeDetectionStrategy.Default
OnPush
CD
OnPush
OnPush OnPush
CD
CD CD
ChangeDetectionStrategy.OnPush
CD
OnPush
OnPush OnPush
CD
CD CD
(EVENT)
ChangeDetectionStrategy.OnPush
CD
OnPush
OnPush OnPush
CD
CD CD
ChangeDetectionStrategy.OnPush
More about Change Detection:
BENEFITS OF USING ONPUSH
• Better application performance
More Tools & Tips
Compodoc: Docs Generator
Strict TypeScript
TypeScript: strictNullChecks
…
…
undefined
11
undefined
NaN
null
33
number
number
undefined null
NaN
11
33
strictNullChecks
null
strictNullChecks
tsconfig.json
Internationalization (i18n)
Internationalization (i18n)
• Store translations in separate files and do not hardcode them in your
components
• Be prepared for multiple languages and dynamic language switches
Angular  use ngx-translate
Building Complex Components
• Use Angular CDK which provides a set of tools that implement common
interaction patterns whilst being unopinionated about their
presentation
• If you build your component also take a look at existing open-source
Angular libraries like Angular Material. There you can see how
components are written the “Angular way”.
• You can also look for existing Angular components in npm, therefore I
can recommend taking a look at curated component lists like Awesome
Angular Components or Awesome Angular.
UI Component
Library
• Put dumb components in
a UI component library
• Use something like
StoryBook to visualize
your components
Augury Browser Dev Tool
Prettier: Opinionated Code Formatter
What is Prettier?
• An opinionated code formatter
• Supports many languages
• Integrates with most editors
• Has few options
Why Prettier?
• You press save and code is
formatted
• No need to discuss style in
code review
• Saves you time and energy
• And more
Misc
• State management: Start with simple state using a service, use NgRx if state
becomes complex
• Use Husky, to check if commit message has the correct format, code is
formatted, linter has no errors and maybe also run unit tests before you push
your code.
• Lazy load all your modules. This way you can split your application in
multiple smaller bundles which are only loaded if necessary.
Corresponding Blog Post
mokkapps
Steps to your next successful Angular project
• Use Nx
• Use DDD
• Implement Error Handling &
Tracking
• Prepare for i18n
• Use available tools
1 of 61

Recommended

ChatGPT and the Future of Work - Clark Boyd by
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
23.4K views69 slides
Getting into the tech field. what next by
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
5.6K views22 slides
Google's Just Not That Into You: Understanding Core Updates & Search Intent by
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
6.3K views99 slides
How to have difficult conversations by
How to have difficult conversations How to have difficult conversations
How to have difficult conversations Rajiv Jayarajah, MAppComm, ACC
4.9K views19 slides
Introduction to Data Science by
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data ScienceChristy Abraham Joy
82.2K views51 slides
Time Management & Productivity - Best Practices by
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
169.7K views42 slides

More Related Content

Recently uploaded

FIMA 2023 Neo4j & FS - Entity Resolution.pptx by
FIMA 2023 Neo4j & FS - Entity Resolution.pptxFIMA 2023 Neo4j & FS - Entity Resolution.pptx
FIMA 2023 Neo4j & FS - Entity Resolution.pptxNeo4j
7 views26 slides
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports by
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug ReportsBushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug ReportsRa'Fat Al-Msie'deen
8 views49 slides
Fleet Management Software in India by
Fleet Management Software in India Fleet Management Software in India
Fleet Management Software in India Fleetable
11 views1 slide
Advanced API Mocking Techniques by
Advanced API Mocking TechniquesAdvanced API Mocking Techniques
Advanced API Mocking TechniquesDimpy Adhikary
19 views11 slides
360 graden fabriek by
360 graden fabriek360 graden fabriek
360 graden fabriekinfo33492
38 views25 slides
Agile 101 by
Agile 101Agile 101
Agile 101John Valentino
7 views20 slides

Recently uploaded(20)

FIMA 2023 Neo4j & FS - Entity Resolution.pptx by Neo4j
FIMA 2023 Neo4j & FS - Entity Resolution.pptxFIMA 2023 Neo4j & FS - Entity Resolution.pptx
FIMA 2023 Neo4j & FS - Entity Resolution.pptx
Neo4j7 views
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports by Ra'Fat Al-Msie'deen
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug ReportsBushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports
Fleet Management Software in India by Fleetable
Fleet Management Software in India Fleet Management Software in India
Fleet Management Software in India
Fleetable11 views
Advanced API Mocking Techniques by Dimpy Adhikary
Advanced API Mocking TechniquesAdvanced API Mocking Techniques
Advanced API Mocking Techniques
Dimpy Adhikary19 views
360 graden fabriek by info33492
360 graden fabriek360 graden fabriek
360 graden fabriek
info3349238 views
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge... by Deltares
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...
Deltares17 views
Sprint 226 by ManageIQ
Sprint 226Sprint 226
Sprint 226
ManageIQ5 views
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx by animuscrm
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
animuscrm14 views
SUGCON ANZ Presentation V2.1 Final.pptx by Jack Spektor
SUGCON ANZ Presentation V2.1 Final.pptxSUGCON ANZ Presentation V2.1 Final.pptx
SUGCON ANZ Presentation V2.1 Final.pptx
Jack Spektor22 views
DSD-INT 2023 The Danube Hazardous Substances Model - Kovacs by Deltares
DSD-INT 2023 The Danube Hazardous Substances Model - KovacsDSD-INT 2023 The Danube Hazardous Substances Model - Kovacs
DSD-INT 2023 The Danube Hazardous Substances Model - Kovacs
Deltares8 views
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J... by Deltares
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
Deltares9 views
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme... by Deltares
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...
Deltares5 views
AI and Ml presentation .pptx by FayazAli87
AI and Ml presentation .pptxAI and Ml presentation .pptx
AI and Ml presentation .pptx
FayazAli8711 views
Quality Engineer: A Day in the Life by John Valentino
Quality Engineer: A Day in the LifeQuality Engineer: A Day in the Life
Quality Engineer: A Day in the Life
John Valentino6 views
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra... by Marc Müller
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra....NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
Marc Müller38 views
DSD-INT 2023 European Digital Twin Ocean and Delft3D FM - Dols by Deltares
DSD-INT 2023 European Digital Twin Ocean and Delft3D FM - DolsDSD-INT 2023 European Digital Twin Ocean and Delft3D FM - Dols
DSD-INT 2023 European Digital Twin Ocean and Delft3D FM - Dols
Deltares7 views

Featured

Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present... by
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
55.5K views138 slides
12 Ways to Increase Your Influence at Work by
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
401.7K views64 slides
ChatGPT webinar slides by
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slidesAlireza Esmikhani
30.3K views36 slides
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G... by
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
3.6K views12 slides
Barbie - Brand Strategy Presentation by
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
25.1K views46 slides

Featured(20)

Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present... by Applitools
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools55.5K views
12 Ways to Increase Your Influence at Work by GetSmarter
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter401.7K views
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G... by DevGAMM Conference
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
DevGAMM Conference3.6K views
Barbie - Brand Strategy Presentation by Erica Santiago
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
Erica Santiago25.1K views
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well by Saba Software
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Saba Software25.2K views
Introduction to C Programming Language by Simplilearn
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
Simplilearn8.4K views
The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr... by Palo Alto Software
The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...
The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...
Palo Alto Software88.4K views
9 Tips for a Work-free Vacation by Weekdone.com
9 Tips for a Work-free Vacation9 Tips for a Work-free Vacation
9 Tips for a Work-free Vacation
Weekdone.com7.2K views
How to Map Your Future by SlideShop.com
How to Map Your FutureHow to Map Your Future
How to Map Your Future
SlideShop.com275.1K views
Beyond Pride: Making Digital Marketing & SEO Authentically LGBTQ+ Inclusive -... by AccuraCast
Beyond Pride: Making Digital Marketing & SEO Authentically LGBTQ+ Inclusive -...Beyond Pride: Making Digital Marketing & SEO Authentically LGBTQ+ Inclusive -...
Beyond Pride: Making Digital Marketing & SEO Authentically LGBTQ+ Inclusive -...
AccuraCast3.4K views
Exploring ChatGPT for Effective Teaching and Learning.pptx by Stan Skrabut, Ed.D.
Exploring ChatGPT for Effective Teaching and Learning.pptxExploring ChatGPT for Effective Teaching and Learning.pptx
Exploring ChatGPT for Effective Teaching and Learning.pptx
Stan Skrabut, Ed.D.57.7K views
How to train your robot (with Deep Reinforcement Learning) by Lucas García, PhD
How to train your robot (with Deep Reinforcement Learning)How to train your robot (with Deep Reinforcement Learning)
How to train your robot (with Deep Reinforcement Learning)
Lucas García, PhD42.5K views
4 Strategies to Renew Your Career Passion by Daniel Goleman
4 Strategies to Renew Your Career Passion4 Strategies to Renew Your Career Passion
4 Strategies to Renew Your Career Passion
Daniel Goleman122K views
The Student's Guide to LinkedIn by LinkedIn
The Student's Guide to LinkedInThe Student's Guide to LinkedIn
The Student's Guide to LinkedIn
LinkedIn87.9K views
Different Roles in Machine Learning Career by Intellipaat
Different Roles in Machine Learning CareerDifferent Roles in Machine Learning Career
Different Roles in Machine Learning Career
Intellipaat12.4K views
Defining a Tech Project Vision in Eight Quick Steps pdf by TechSoup
Defining a Tech Project Vision in Eight Quick Steps pdfDefining a Tech Project Vision in Eight Quick Steps pdf
Defining a Tech Project Vision in Eight Quick Steps pdf
TechSoup 9.7K views

How I Would Start A New Angular Project

Editor's Notes

  1. Opiniated Release cycles & LTS DI, Forms, Router, TS, RxJS included
  2. Nx is an easy to use version of the powerful monorepo tools used at companies like Google
  3. Shared package.json Multiple technologies
  4. Build a graph which will never be out of sync! An Nx workspace can contain dozens or hundreds of applications and libraries. As a codebase grows, it can be difficult to understand how they depend on each other and the implications of making a particular change.
  5. Free for personal projects and early-stage applications View actual code in stack traces for over 32 languages and frameworks. stack traces Backend & frontend error tracking Trail of events by using breadcrumbs Version changes
  6. Snapshot testing is great. It lets you capture a string that represents your rendered component and store it in a file. Then you can compare it later to ensure that the UI didn't change
  7. Selenium executes in a process outside of the browser or device we are testing Cypress executes in the browser and in the same run loop as the device under test.
  8. supports all major APIs of Angular Open-source and on npm No server needed, no sources uploaded online Search engine 7 themes & responsive
  9. Angular CDK Angular Material code snippets GitHub curated component collections
  10. When an array changes, Angular re-renders the whole DOM tree. But if you use trackBy, Angular will know which element has changed and will only make DOM changes for that particular element.
  11. NgRX: you build an application with a lot of user interactions and multiple data sources, when managing state in services are no longer sufficient. Lazy load: reduce the size of the application to be loaded improve the application boot time by not loading the modules that are not used.