I am currently utilizing UI-Router for Angular and have set up separate views for my app: sidebar and main. Now, I find myself in a situation where I need to alter a class in the main view following an action taken in the sidebar view.
Below is the code snippet:
Config
.state('app.area', {
url: '/area/:areaId',
views: {
'@': {
template: require('./app/generic/genericWithSidebar.html'),
controller: 'AreaCtrl'
},
'<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2548444c4b654455550b0">[email protected]</a>': {
template: require('./app/area/_area.html'),
controller: 'AreaCtrl',
controllerAs: 'CTRL',
},
'<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="27544e4342454655670">[email protected]</a>': {
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;
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 am looking for a way to establish communication between the views without involving additional controllers since I only have one controller.