I'm using UI-Router for Angular and I have separated views for my app: sidebar and main. Now i need to change some class in main view after some action that does in sidebar view.
So, this is my code:
config
.state('app.area', {
url: '/area/:areaId',
views: {
'@': {
template: require('./app/generic/genericWithSidebar.html'),
controller: 'AreaCtrl'
},
'[email protected]': {
template: require('./app/area/_area.html'),
controller: 'AreaCtrl',
controllerAs: 'CTRL',
},
'[email protected]': {
template: require('./app/area/_sidebar.html'),
controller: 'AreaCtrl',
controllerAs: 'CTRL',
}
},
controller
class AreaCtrl {
constructor($scope) {
"ngInject";
this.$scope = $scope;
this.$scope.descriptionIsActive = false;
}
showAreaDescription() {
this.$scope.descriptionIsActive = !this.$scope.descriptionIsActive;
}
}
export default AreaCtrl;
and views for sidebar and main
// sidebar view
<span ng-click="CTRL.showAreaDescription()">show more</span>
// main view
<div ng-class="{'active': CTRL.descriptionIsActive}"></div>
I need to communicate between views, not controllers, i have one controller.
AreaCtrleach with it's own scope