Click here to Skip to main content
15,903,817 members
Home / Discussions / JavaScript
   

JavaScript

 
AnswerRe: Array Question Pin
Nathan Minier11-Jan-16 2:13
professionalNathan Minier11-Jan-16 2:13 
QuestionStatic Clock Pin
Mindlesscandi10-Jan-16 16:00
Mindlesscandi10-Jan-16 16:00 
AnswerRe: Static Clock Pin
Richard MacCutchan10-Jan-16 21:02
mveRichard MacCutchan10-Jan-16 21:02 
QuestionDisplay web page on mobile as overview with zoom-in on detail Pin
Member 122502747-Jan-16 5:49
Member 122502747-Jan-16 5:49 
AnswerRe: Display web page on mobile as overview with zoom-in on detail Pin
Nathan Minier8-Jan-16 2:16
professionalNathan Minier8-Jan-16 2:16 
QuestionHow to load all the images from a folder on local with only javascript? Pin
phinq19102-Jan-16 7:04
professionalphinq19102-Jan-16 7:04 
QuestionRe: How to load all the images from a folder on local with only javascript? Pin
ZurdoDev8-Jan-16 2:55
professionalZurdoDev8-Jan-16 2:55 
QuestionHow to create my Model/Objet/Data layer in my MVC pattern in AngularJS Pin
glassShot10030-Dec-15 18:31
glassShot10030-Dec-15 18:31 
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

JavaScript
app.controller('BookController', ['$scope', function($scope) {  
    $scope.book = {
        id: 1,
        name: 'Harry Potter',
        author: 'J. K. Rowling',
        stores: [
            { id: 1, name: 'Barnes & Noble', quantity: 3},
            { id: 2, name: 'Waterstones', quantity: 2},
            { id: 3, name: 'Book Depository', quantity: 5}
        ]
    };
}]);



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:

function Apple (type) {
    this.type = type;
    this.color = "red";
}
 
Apple.prototype.getInfo = function() {
    return this.color + ' ' + this.type + ' apple';
};


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
AnswerRe: How to create my Model/Objet/Data layer in my MVC pattern in AngularJS Pin
Nathan Minier5-Jan-16 6:47
professionalNathan Minier5-Jan-16 6:47 
QuestionPrompt Box Pin
Mindlesscandi23-Dec-15 22:20
Mindlesscandi23-Dec-15 22:20 
AnswerRe: Prompt Box Pin
Anurag Gandhi27-Dec-15 7:49
professionalAnurag Gandhi27-Dec-15 7:49 
GeneralRe: Prompt Box Pin
Mindlesscandi30-Dec-15 23:28
Mindlesscandi30-Dec-15 23:28 
AnswerRe: Prompt Box Pin
Beginner Luck28-Dec-15 14:43
professionalBeginner Luck28-Dec-15 14:43 
GeneralRe: Prompt Box Pin
Mindlesscandi30-Dec-15 23:27
Mindlesscandi30-Dec-15 23:27 
AnswerRe: Prompt Box Pin
Abhishek Vats12-Jan-16 9:30
professionalAbhishek Vats12-Jan-16 9:30 
QuestionHow to open popup in new window in IE11 using javascript Pin
ven75323-Dec-15 17:29
ven75323-Dec-15 17:29 
AnswerRe: How to open popup in new window in IE11 using javascript Pin
Anurag Gandhi27-Dec-15 1:19
professionalAnurag Gandhi27-Dec-15 1:19 
SuggestionRe: How to open popup in new window in IE11 using javascript Pin
ZurdoDev4-Jan-16 2:37
professionalZurdoDev4-Jan-16 2:37 
Questioncoding Pin
Member 1219583817-Dec-15 23:52
Member 1219583817-Dec-15 23:52 
AnswerRe: coding Pin
Richard Deeming18-Dec-15 2:53
mveRichard Deeming18-Dec-15 2:53 
AnswerRe: coding Pin
ZurdoDev18-Dec-15 3:26
professionalZurdoDev18-Dec-15 3:26 
QuestionHow to force loading automatic javascript Pin
TaRoshka16-Dec-15 22:57
TaRoshka16-Dec-15 22:57 
AnswerRe: How to force loading automatic javascript Pin
ZurdoDev18-Dec-15 3:27
professionalZurdoDev18-Dec-15 3:27 
AnswerRe: How to force loading automatic javascript Pin
Beginner Luck4-Jan-16 15:44
professionalBeginner Luck4-Jan-16 15:44 
Questionproblem in connectivity oh java with mysql Pin
Sagar Singh Rathee12-Dec-15 17:18
Sagar Singh Rathee12-Dec-15 17:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.