My controller calls factory Action
and adds buttons on the page I'm loading, see below controller:
class AgenciesListController {
/* @ngInject */
constructor(Action) {
this.action = Action;
this.action.addButton({
title: 'Nova Agência',
state: 'agencies.new'
});
}
}
export default AgenciesListController;
The factory Action
, simple, has the functions of adding and catching all the buttons added:
const ActionFactory = () => {
let buttons = [];
return {
addButton: (button) => buttons.push(button),
getButtons: () => buttons
};
};
export default ActionFactory;
I want to change the page, just display the buttons on the selected page, if a page does not have buttons in its controller, nothing should be displayed.
The code above causes unwanted behavior by adding new buttons every time the page is selected from the menu.
Should I reset the buttons
array every time I change pages?