Doubt - Angular Controllers

Asked

Viewed 64 times

4

I’m studying Angular and I have a question. I’m creating an application, and wanted to organize the controllers by creating one for each view (template).

Exemplo:
Tela Cadastro - controller-cadastro.js
Tela Login - controller-cadastro.js
Tela Vídeos - controller-videos.js

Can I create a controller for each view? Is this logic correct? There is a smarter and more usual way for a controller to control a different view and keep the file structure split?

  • "I can create a controller for each view?" You can, you can create as many as you want. "This logic is correct?" What logic? This is a matter of organization, do it the best way for you. "There is a smarter and more usual way for a controller to control a different view and keep the file structure split?" I didn’t get that part.

  • @jbueno my question of summarized form is, if I could create the controllers in separate files

  • 2

    You can, man. You can do whatever you want.

1 answer

3


You can have a Controller for view, but the important thing is to recognize that the concept of Controller serves to separate the application scopes. The Controller decouples the format of the presentation data. For example, you may have client data but do not want to show all of them in particular view.

Taking advantage of your doubt and noting that you are interested in the best way to program using Angularjs, a good material of good practices that is the Angular Style Guide.

  • Thanks man, I got it. My question was if I could create the controllers in separate files, you know?

  • @Juliorodrigues Was the answer helpful to you? Don’t forget to mark it so it can be used if someone has a similar question!

  • valeu man, it was yes!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.