Trying to use a reusable controller for a generic template
html
<div class="row col-lg-10 pull-right">
<div ng-init="catId = 1" ui-view="firstQuadrant"></div>
<div ng-init="catId = 2" ui-view="secondQuadrant"></div>
</div>
<div class="row col-lg-10 pull-right">
<div ng-init="catId = 3" ui-view="thirdQuadrant"></div>
<div ng-init="catId = 4" ui-view="fourthQuadrant"></div>
</div>
code snippet from my views object in $stateProvider:
views : {
'firstQuadrant@home': {
templateUrl: "../partials/quadrant/quadrant.html",
controller: "QuadrantCtrl"
},
'secondQuadrant@home': {
templateUrl: "../partials/quadrant/quadrant.html",
controller: "QuadrantCtrl"
},
'thirdQuadrant@home': {
templateUrl: "../partials/quadrant/quadrant.html",
controller: "QuadrantCtrl"
},
'fourthQuadrant@home': {
templateUrl: "../partials/quadrant/quadrant.html",
controller: "QuadrantCtrl"
}
}
controller code
.controller('QuadrantCtrl', ['$scope', '$rootScope', 'categories', 'utils',
function ($scope, $rootScope, categories, utils) {
$scope.$watch('catId', function () {
console($scope.catId);
$scope.categories = categories;
$scope.name = "It works! weee";
$scope.score = 99;
$scope.items = utils.findById($scope.categories, $scope.catId);
});
}]);
It only seems to use the last controller being instantiated (catId = 4) how can I have 4 isolated scopes? Do I have to use directives instead?