mardi 30 août 2016

Angular design pattern of adding classes to body

I have a design problem. The website has two aside menus. When I click on one of them, body block needs additional classes (_openLeftAside and _openRightAside). So what is the best way to implement such behavior? Currently, I have LayoutController, that handles clicks.

function LayoutCtrl($rootScope) {    
  const vm = this;

  vm.activeAside = ASIDE_LEFT;

  vm.changeAside = () => {
    vm.activeAside = (vm.activeAside === ASIDE_LEFT ? ASIDE_RIGHT : ASIDE_LEFT);
    return vm.activeAside;
  };
}

Should it broadcast event to BodyController / $rootScope and set class on body with ng-class? Or should I create a directive, that will manipulate body classes (but I can't quite understand how to implement it properly)?

Aucun commentaire:

Enregistrer un commentaire