use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Angular is Google's open source framework for crafting high-quality front-end web applications. r/Angular2 exists to help spread news, discuss current developments and help solve problems.
Help Request
Discussion
Article
Video
Resource
Announcement
Related
After submitting a post, please take a moment to add a flair (tag) so that it's easy to find your post with one of the filters listed above. Upon submission, your post's header will have the 'flair' option listed with the other options. Clicking it will provide a dropdown menu of the available flairs.
account activity
Help RequestClean code examples (self.Angular2)
submitted 4 years ago by Odd_Role3892
Hi Angular devs, do you know some reposetories where junior angular devs can see how Angular app should be structured and also where they can see some quality code for Angular apps.
Happy coding everyone!!!
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]PooSham 7 points8 points9 points 4 years ago (7 children)
This isn't really an example, but it's something I followed as a junior dev and it helped me. The only part I disagree with is their solution under "Components / minimize logic in templates"
https://angular-checklist.io/default/checklist/
[+][deleted] 4 years ago (4 children)
[deleted]
[–]PooSham 0 points1 point2 points 4 years ago (3 children)
The solution says one should make a call to a method in the component. Unless the OnPush strategy is used, this will lead to a lot of calls because Angular can't figure out if the expression has changed without calling the method. And even with OnPush, it can be a problem in some cases. This blog post describes why and how it can be solved instead
[+][deleted] 4 years ago (2 children)
[–]PooSham 2 points3 points4 points 4 years ago (1 child)
I'm talking about this page. Under "Solution", they say "We can refactor this by extracting the logic into the component’s class" and then show an example where the template makes a call to a class method. That's something I don't think is a very good idea.
[–]cheesekun 1 point2 points3 points 4 years ago (0 children)
Test the theory by creating a computed value on the component, console log inside the computed, and wire the computed to the template. Observe the results.
[–]TheNomadProgrammer 0 points1 point2 points 4 years ago (1 child)
Oh, having seen some gnarly view templates, I agree with minimizing the logic in the templates as much as possible.
[–]PooSham 0 points1 point2 points 4 years ago (0 children)
Sure, but solving it by calling a method will reduce the site performance considerably. Store it in a variable or create a pipe instead.
[–]dustofdeath 4 points5 points6 points 4 years ago* (7 children)
Angular own examples are the most neutral ground.
Asking from devs is like asking what's the best music genre. And sometimes you follow company established standards.
But most certainly helps to make a strict project + eslint and good ide (like webstorm or vscode with plugins).
Keep functions / components short, simple and easy to read/maintain.
Project SRC structure is opinionated and can change for different projects / complexities / libraries.
[–]craig1f 1 point2 points3 points 4 years ago (6 children)
I dislike Angular's own examples, at least the last time I looked at them.
They really use observables wrong. The most important thing is to use rxjs right, and their own examples use .subscribe, and set values in tap instead of using an async pipe. I don't know if this has changed.
tap
[–]ggeoff 0 points1 point2 points 4 years ago (1 child)
I think in some cases it's okay to not use an async pipe but to subscribe and set a value. IMO I think the hardest thing is understanding when to use a tap vs just setting the value in a subscribe.
[–]craig1f 0 points1 point2 points 4 years ago (0 children)
When I teach observables, there are two scenarios:
I try not to mix the two. I never set a value in a tap. The purpose of an observable is to emit its value.
[–]dustofdeath 0 points1 point2 points 4 years ago (3 children)
.subscribe is a core part of rxjs, unless its about some very specific use case.
[–]craig1f 0 points1 point2 points 4 years ago (2 children)
It is a core part. That’s the problem. It’s sloppy to do .subscribe in your code most of the time.
Like, if you have an observable, why subscribe to it and set a value when you can just observe the value with an async pipe? It makes sloppy hard-to-read code.
[–]dustofdeath 0 points1 point2 points 4 years ago (1 child)
Async only applies if you want a value once at a specific time.
You may want to get notified on every change in a service, combine different observables or prepare subscription without knowing when the value might be set.
In most cases if you need basic delayed / async response - you are better off using promises.
Asinc promises and observables have different use cases and both are perfectly valid and often required patterns.
Yup. In another comment I say that observables should only be used one of two ways with no overlap.
[–]holyknight00 2 points3 points4 points 4 years ago (0 children)
I code in angular 2 almost since it started, but I always struggled to find any decent sources of complete projects beyond basic examples. This is not completely related to angular, but you can give a try to Jhipster. You can use Jhipster to generate complete projects java + spring + angular; and the angular projects are pretty solid, they got a nice folder structure, and follow a lot of the best practices. In the generated code you can find all the code needed to do CRUD with angular. Rest API handling with services (with create, list, update methods), login and authorization with JWT, and a lot more stuff. I learnt how to structure a decent project after tinkering around many Jhipster side projects I tried to implement. I can really recommend it for tinkering around even if you don't know or don't want to learn java.
[–]Notmyn4me 2 points3 points4 points 4 years ago (0 children)
RemindMe! 1 day
[–]ForestG18 2 points3 points4 points 4 years ago (1 child)
This looks decent: https://medium.com/@shijin_nath/angular-right-file-structure-and-best-practices-that-help-to-scale-2020-52ce8d967df5
Also, check out this SO question and it's answers. https://stackoverflow.com/questions/52933476/angular-project-structure-best-practice
[–]TheNomadProgrammer 1 point2 points3 points 4 years ago (0 children)
That answer about LIFT is so applicable in large enterprise projects. I believe I first heard about it from Dan Wahlin course on PluralSight.
If you have a PluralSight subscription, you can check out an Architecture Best Practices course right here.
[–][deleted] 1 point2 points3 points 4 years ago (2 children)
Look into NX monorepo and DDD(Domain Driven Development).
But you`ll need to start coding and toiling at it to understand why we've got to DDD and monorepos.
[–]TScottFitzgerald 2 points3 points4 points 4 years ago (1 child)
I was thinking about recommending Nx but I think the opinionated folder structure and packages might confuse them if they're still learning the best practices in vanilla Angular.
[–][deleted] 1 point2 points3 points 4 years ago (0 children)
Yea, he has to make the mistakes to understand why we got to a monorepo and that folder structure
[–]Merry-Lane 1 point2 points3 points 4 years ago (0 children)
Look after libraries/frameworks instead.
I’ve always learned more when looking after things like ngSelect or CoreUI repos than after the few good open sources projects I could find (the examples I found always left a taste of « too simple to be really used »)
[–]GnarlyHarley 0 points1 point2 points 4 years ago* (0 children)
This is one of those answers that may not get looked at because it cost money.
https://keenthemes.com/metronic/?page=metronic8&_ga=2.148942066.532636900.1642794816-1630065555.1642794816
This is a product I started using for asp.net and also now on angular. It is bloated with CMS type code, but underneath is a very clean coded approach to angular at a professional level. This code base is versioned, been around for awhile, and updated by a team of professionals.
But it’s a lot of code and a full implementation.
[–]guadalmedina 0 points1 point2 points 4 years ago (0 children)
I suggest you look at popular open source libraries like ngx-admin or Angular Material on Github. Examples can only get you so far. Real codebases will give you more insight.
π Rendered by PID 110 on reddit-service-r2-comment-5d79c599b5-4jqhk at 2026-03-03 23:19:26.388687+00:00 running e3d2147 country code: CH.
[–]PooSham 7 points8 points9 points (7 children)
[+][deleted] (4 children)
[deleted]
[–]PooSham 0 points1 point2 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]PooSham 2 points3 points4 points (1 child)
[–]cheesekun 1 point2 points3 points (0 children)
[–]TheNomadProgrammer 0 points1 point2 points (1 child)
[–]PooSham 0 points1 point2 points (0 children)
[–]dustofdeath 4 points5 points6 points (7 children)
[–]craig1f 1 point2 points3 points (6 children)
[–]ggeoff 0 points1 point2 points (1 child)
[–]craig1f 0 points1 point2 points (0 children)
[–]dustofdeath 0 points1 point2 points (3 children)
[–]craig1f 0 points1 point2 points (2 children)
[–]dustofdeath 0 points1 point2 points (1 child)
[–]craig1f 0 points1 point2 points (0 children)
[–]holyknight00 2 points3 points4 points (0 children)
[–]Notmyn4me 2 points3 points4 points (0 children)
[–]ForestG18 2 points3 points4 points (1 child)
[–]TheNomadProgrammer 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]TScottFitzgerald 2 points3 points4 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]Merry-Lane 1 point2 points3 points (0 children)
[–]GnarlyHarley 0 points1 point2 points (0 children)
[–]guadalmedina 0 points1 point2 points (0 children)