javascript - Critical view on object based application structure in AngularJS -


as tried learn angular in past weeks, have adopted application architecture.

assuming intermediate large spa, create view , apply maincontroller:

<html ng-app="app">     <body ng-controller="appctrl">         <!-- of view goes in here -->     </body> </html> 

now think stuff application have do. assuming 1 have store data , working it, create provider build "class".

    var data = angular.module('data', []);  data.provider('$dataobject',function(){      this.$get = function($http){              function dataobject(){                  var field = "testvalue";                 var object = {                     // ...                 }             }              dataobject.prototype.processdata = function(){                //             };          return {             shipment: function(){                 return new shipment();             }         }     } }); 

i create instance of class in maincontroller, storing of necessary data view object, processing calling class methods.

if application need functionality, e.g dialog pick stuff, repeat steps above , create class dialog.

now, while quite comfortable things way, still wonder if consider bad practice, , if so, why , better?

creating services/providers models/data (with apis expose data), , injecting them controllers "angular way."

when design angular app, think models need , create services them. (or in parallel) think views , design those. create custom directives @ point also. lastly, each view gets controller, job glue models/data services view needs. (make controllers thin possible.)


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -