Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a largish Angular app, with one 'master' view, with menus etc. and this then loads 'child' views into a sub-portion of the 'master' page. The master page (every page, in effect) has a good few navigation buttons, like 'Home', 'New Doc', 'Logout', etc.

Each child page has some buttons, but one special button with an ng-really-click directive, where a `SaveAndClose` function is named. This is almost exactly plain ng-click, but it pops up a confirmation before executing the on-click function. I need to incorporate this `SaveAndClose`function for whichever document or document type is currently active, i.e. displayed in the master page.

My first attempt at this, e.g. when the 'Logout' button is pressed, I extract from the child-page its `Close` link and simply pull the function from that button's ng-really-click attribute, and dynamically execute that function, but then my problem with scope, was that the `SaveAndClose` function needed access to two scopes, that of where is is normally called. and my master page.

I factored the actual save code into a service, into which I inject the scope of the controller using the service, and calling `SaveAndClose`, with its needed accesses to external scope.

My second approach was to modify the ng-really-click directive, to suppress the confirmation popup, and then e.g. when mentioned 'Logout' button is pressed, it will simply simulate a 'click' event on the child page button that is supposed to call SaveAndClose.

Because the second approach is much closer to what I would like, which is really clicking the damned ng-nearly click button and have it avoid the popup, but do what it is supposed to do, instead on trying to make the 'master page' button determine and fulfill what the child button does.

However, dynamically calling a function expression in a variable on an external scope stored in a variable seems much harder than simply simulating a button click, but many hours experience last night proved neither is a walk in the park.

How can I properly achieve forcing a `click` on the `SaveAndClose` button, or is this really barking up the wrong street? Please bear in mind, this is a fairly large codebase and I am a total Angular noob.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900