You start punching out mad code. You set up services, filters, directives and a whole bunch of controllers. It’s all gorgeous. AngularJS makes you write good code. Everything sort of naturally falls into place and even as the code base grows, it never gets unweildy. When you, in brief moments of insanity, try to work against the framework, it prompty punishes you. Not because it is cruel, but to protect you from making architectural mistakes. Monstrosities in unmaintainability. You chant the mantra: “testability, dependency injection, modularity”, and figure it out. You didn’t need to create a class in order to contain that piece of conversion logic, you needed a filter. Everything is right again.
Eventually you end up at the point where one controller needs to talk to another controller. And AngularJS fails you. Now really, this isn’t a failure on AngularJS’s part at all, but rather just a result of keeping all dependencies handled by a DI framework. Your controller has some state, and another controller also wants the same state. This could be a username, a config object, just about anything. Of course, now you see it.You need a service.
Your new post is loading...