AngularJS: Nested Controllers and Models -


i'm learning how use angularjs building small app. i'm little confused controllers , models. have 3 controllers, 2 of nested.

<div ng-controller="controller1 ctrl1">     <div ng-controller="controller2 ctrl2">         <div ng-controller="controller3 ctrl3">         </div>     </div> </div> 

i using different model each controller display data. of data related in 1 way or another, wondering if should using 1 model instead. , if so, should defined?

for example, 1 controller might like

(function() {      angular         .module('app')         .controller('controller1', controller1);      function controller1() {          this.data = data;     }      var data = [             {             name: 'data 5',         },         {             name: 'data 6',         },         {             name: 'data 7',         }     ]; })(); 

where model defined in data. other controllers have models different names.

since have related data shared (or not) , changing every 10-60 seconds, i'd suggest using single service. within service, instantiate many data sets need matching getters/setters.

services persist data 1 controller modifies data in service, other controllers utilizing service have access same updated data well.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -