generator-cg-angular icon indicating copy to clipboard operation
generator-cg-angular copied to clipboard

Alternative approach to the partial generator

Open gabbsmo opened this issue 9 years ago • 1 comments

Much have happened over the years and I've found some interesting thoughts that are not yet implemented in any mainstream build systems.

Combining directives with controllerAs and isolated scope The controllerAs syntax was introduced in 1.2 and makes controller functions more vanilla JavaScript and less coupled with Angular. Putting the logic of a directive in a controller with isolated scope allows the directive to be moved around freely since it by definition don't have a dependency on the parent scope. I see this as an alternative to the current partial sub generator.

Defining controllers in closures Defining a controller function as a named JavaScript closure and then registering it with Angular's DI makes the code more readable and stack traces will be more informative.

gabbsmo avatar Nov 22 '14 15:11 gabbsmo

Those are two really thought provoking blog posts. The post about using directives instead of controllers is really smart but I don't think I'm ready to dump controllers just yet. I agree with alot of those points but not sure the solution is better than the issues. Also, the "Poor View organization" is not a problem if you use this generator.

The second one is a bit less radical. Today, this generator doesn't use the controllerAs syntax but that should probably change. After that, if you choose to have your controller return an object to help isolate what is exactly on the controller, I think you could do that with little help from the generator.

cgross avatar Nov 28 '14 17:11 cgross