Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How to create my Model/Objet/Data layer in my MVC pattern in AngularJS

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new in Javascript web applications, I'm more used to creating java/Spring c#/.Net applications, I'm also not a guru in those, though.

What I always do when I create a web application using MVC pattern I do the following:

I create the following folders to organize my code

-View folder: here I put all the HTML files

-Controller folder: here I put all my methods that call the necessary methods to bring me the data that's needed in the views.

-Service folder: here I put all the methods that go to the database to bring info and other necessary methods from the business logic.

-Model folder: here I put all my classes with the attributes example (User class, Role class, Vehicle class, etc).

Example:
public class User {
private name;
.....
getters and setters...
}

I want to apply the same or a similar concept to my Javascript/AngularJS tutorial learning app

So far I have created a very simple app a calculator app with the Service Layer, Controller Layer and View Layer and they work as I expected to work,

the service layer: have all the methods like add, subtracts, multiply.
the view layer: have the html where I input the numbers.
the controller layer: have the method that calls the service and then I pass the data to the view.

BUT my problem is that I don't know how the Model fits in a AngularJS app I have see that some tutorials put the model objects inside the controllers like this





but I don't know if that's the way because if I need a model object in another controller do I need to declare the same code in the other controller??

Also how should I deal with model objects that have inside other model object lets say Users have roles inside them.

where should I put my model objects like User, Role, Vehicle etc? Is there a good approach if I create a .JS file named model.js and put there all the objects like this:



But I have read about the global scopes and bad practices etc I actually don't know too much about that if I create that file model.js with my model objects would I be creating a problem?

I'm very open to suggestions since I'm learning
 
I am going to test your electrical conductivity with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic