I'm learning how to use AngularJS by building a small app. I'm a little confused about controllers and models. I have 3 controllers, 2 of which are nested.
<div ng-controller="Controller1 as Ctrl1">
<div ng-controller="Controller2 as Ctrl2">
<div ng-controller="Controller3 as Ctrl3">
</div>
</div>
</div>
I am using a different model for each controller to display data. All of the data is related in one way or another, so I am wondering if I should be using one model instead. And if so, where should it be defined?
For example, one controller might look 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 the model is defined in data. The other controllers would have models with different names.