0
My controller calls Factory Action
and adds buttons on the page I’m loading, see below the controller:
class AgenciesListController {
/* @ngInject */
constructor(Action) {
this.action = Action;
this.action.addButton({
title: 'Nova Agência',
state: 'agencies.new'
});
}
}
export default AgenciesListController;
A Factory Action
, simple, has the functions to add and grab all the buttons added:
const ActionFactory = () => {
let buttons = [];
return {
addButton: (button) => buttons.push(button),
getButtons: () => buttons
};
};
export default ActionFactory;
I wish that when changing page, only show the buttons of the selected page, if a page has no buttons in its controller, nothing should be shown.
The above code brings an unwanted behavior by adding new buttons every time the page is selected by the menu.
I must reset the array buttons
every time you change page?