I’m a big fan of Angular, I’ve been using it for years now, for a variety of projects. I’ve written about it and helped others learn it. One thing that I have noticed that a lot of developers who start using Angular who have come from a different technology stack, is that they try to apply the style and approach they have in another framework or language to Angular. This can lead to extremely messy code or Angular code that is hard to maintain as a project grows.
The reason I feel this happens is Angular is an opinionated framework, there is an approach you take to write Angular apps. If you try to ‘build’ an Angular app in a way that goes against this approach, then things can start to go wrong.
In Angular there are some things you should do:
- Split your functionality into modules
- Use services for complex code
- Keep components light, not too much complex code should be in your components
- Make use of the DI system that Angular comes with
- Write tests
- Follow the Angular style guide
Now one of the main complaints against Angular is that it has a steep learning curve compared to other frameworks. This is true, if you come from an HTML/CSS/JS background, the concepts of services, components and DI may be new to you. But with Angular having strong opinions on how an app should be built this learning curve is not as steep as people believe.
A lot of projects I've seen have been worked on by developers with a lot of experience who have started on a project that uses Angular, which might not be their main skillset. So they try to write Angular in a way that they know how to build apps in another framework or technology, usually, I've seen this when a developer who knows something like C# or Java and they've been given the job of building out a web UI for the backend stack. They then try to write Angular using the approach they know, using the concepts from .Net webforms for example.
This can lead to really hard to maintain code and an Angular application that has many problems, that only get worse as the project grows, but there is no need for this.
With Angular be opinionated on how an app should be built through following the approach that the Angular team have set out. You can have a stable application, that is easy to maintain and that can scale over time.
There's great documentation out there showing examples of different types of Angular apps, the Tour of Heros from the official docs is a great example. It clearly shows how you should write an Angular app. This along with the style guide makes it clear what the Angular way is.
So Angular being opinionated is a good thing, if you want a front-end framework that your team can all work together on and have a common approach then Angular might be the framework for you.