Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I want to know what's that proper way to handle the business logic in terms of loading the appropriate views and controllers.

I have a bunch of factories to load resources, read and write user progress (to a local file) and so forth. The user will spend no more than several seconds on a given view (there are 6-7 different ones in total) and will switch to another one with dynamically loaded resources based on his progress.

My current idea is to have a service/factory that keeps track of progress, which is loaded on the index page and then every controller sends a request to it, once it's finished. Thereafter the service changes the $state and loads the appropriate data.

I'm building my first app in AngularJS and I have tried to search StackOverflow and Google, but I still can't figure out how to approach this problem.

Even pointing me to the right direction or reading material would be greatly appreciated.

share|improve this question
    
I think you need to read about angular DI and design pattern – R.J Aug 25 at 11:08

If you are creating AngularJs app first time then follow simple steps.
1. Create one index.JSP file where you should run your app using ng-app directive and add all scripts and files.
2. create one Js file app.js.
add all module name in app.js and run your js using .run method.
3. maintain services, controllers and filters, directives, templates seperately in different folders and in different files.
And dont forget to add module name in app.js and add path in index.jsp
4. In your services files write only sharing business logic.
All other business logic related to particular file write it in controller.
Here your are maintaining ajax calls so dont meshup it with controllers.

.Service

.factory('angularService', function () {
  return {
    // Write business logic
  }
})
  1. Declare $starteProvider and define .states in your controller.

For ex.

$stateProvider.state('xyz_state', function () {
   // add url,
   // templateUrl,
   // controller
})
.controller('myFirstController', function () {
   // Add your business logic
   // scope variables
});  

6. Maintain view pages separately.
7. Maintain Directives and Filters separately.

share|improve this answer

I usually use the $templateCache & store all my views there. if your on Node environment i'd suggest add ng-html2js to your build process.

as for controllers & other JS you should minify and concat all and load just that file in the beginning.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.