Dynamic controller

If I have 50 html pages I want to put in an App - do I have to make 50 controllers (one for each) or is there a way to dynamically use the same controller over again?

If you mean 50 html pages, but 40 of them are repeating in ui logic (only the content is changing). Then sure, you can use a single controller with different params passing in to tell the controller to grab different content.

If you mean 50 html pages with 50 different UI and “important and different” business logic, seriously you should make 50 controllers.

If you mean 50 html pages with 50 different UI but business logic may be used and reused, use a root controller at body to inject some service to the page and not all of the 50 views needs an “actual” controller, you can directly call the method from a service.

Hi windht,

I am making an app with list of allergy-friendly food.

I start with listing categories:

  • Fruit
  • Vegetable
    and so on…

If you click fruit I list ther different fruit and which one are allergy-friendly (Green dot)

  • Apple
    -Banana

So far so good.
If you click Apple, I want a detail page for Apple with a title, text, an image and so on.

I could not figure out how to pass parameters from Apple on the list to an Apple detail page.
My “workaround” was just to make a static html for apple, banana and so on…

You can see the files here:
https://github.com/moochie23/AllergyApp

hi danielnn

It is not required to have same controller as many as html pages.

See it is basically depends on your business logic.If it is critical business logic then you should go for separate controller for that html page.

But you can also filter out common functionality through out the pages and make a services that can be injected in controller.

And you can also manipulate multiple pages with same controller, it is depends on you as well. :smile:

hi danielnn

It is not required to have same controller as many as html pages.

See it is basically depends on your business logic.If it is critical business logic then you should go for separate controller for that html page.

But you can also filter out common functionality through out the pages and make a services that can be injected in controller.

And you can also manipulate multiple pages with same controller, it is depends on you as well. :smile: