javascript - AngularJS: need a best practice for hierarchical data -


i new angular, watched number of videos , read docs, not sure have compiled in mind. i've seen bunch of small simple pieces of code never saw complex. know of docs/tutorials/examples me implement following?

i want make spa forum web application. forum consists of numerous topic groups, each of has topics inside, , each topic has multiple comments.
hierarchy of nested entities this: forum -> topic group -> topic -> comment.
in spa i'll need crud of them or load server either single entity (say comment) or complex view (a topic comments) depending on user/admin wants.

i can't find example dealing complex hierarchies. should controllers , models nested or separated? how should separate crud methods? put them top level of $scope? how separate parent/child entities of same $scope used in different controllers? better way substitute view , edit templates data being edited user? etc...

or better, there sample task mine?

thanks

i avoid nesting controllers (making controllers depends on scope of parent controllers), , instead make custom services through controllers communicate.

routing of controllers biggest issue me. i've started using nginclude , handling routing manually, because angularjs doesn't allow multiple ngviews. solution angular ui router. have a simple example can give idea on how structure navigation.

basic principle is:

  • any view can have sub view (and it's controller therefore contains sub-controller)
  • controllers in hierarchy don't communicate directly through $scopes. rather should use services or events ($scope.$emit, $scope.$on)
  • any level of depth can routed (e.g. http://myforum.com/#/help-category/how-do-i/msg1)

take view grain of salt because i'm new angular.


since you're interested in scope inheritance here's example, discouraged communication between controllers.

when controller has parent controller, it's scope has parent scope:

parent controller:

$scope.breakfast = 'eggs'; alert($scope.breakfast); // shows eggs 

child controller:

alert($scope.breakfast); // shows eggs, inherited value $scope.breakfast = 'muesli'; alert($scope.breakfast); // shows muesli, new value 

parent controller:

alert($scope.breakfast); // shows eggs, value remained same $scope.breakfast = 'burek'; // child doesn't see change anymore 

you can better description , illustrations in angulars developer guide.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -