Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

REQUEST FOR FEEDBACK: angular.component() - auto creating a controller #13683

Closed
@shairez

Description

@shairez

As discussed with @shahata and @petebacondarwin -

The problem I run into when writing lots of "component like" directives is the unnecessarily repeated configuration over and over again.

Registering controllers

It's redundant to have a separate controller declaration.

Registering controllers by name in a component based architecture is useful only for unit tests, where you'd want to use $controller to create an instance of the component's controller.

But registering it over and over again is redundant and can be done by the .component.

We should have one .comp.js file

If we use .component(), it should auto create a new controller, registered with the same component name (because it too must be unique).

So we should end up with one file where the .component() becomes a true "annotation like" thing, something like:

angular
 .module('myModule')
 .component('productList', {
   controller: ProductListController,
   templateUrl: 'product-list.comp.html'
  })

function ProductListController(){

}

$controller('productList') // <-- should be an instance of ProductListController

I'd love to hear the cons for this approach

What do you think?

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions