Search code examples
javascriptangularjsangularjs-scopecontrollers

angularjs multiple controllers on one page


I have a page with multiple controllers, one of the controller is being used in 2 different divs within the same page. I am not sure if it is a scope issue or I just miss something in my code.

here is the plunkr http://plnkr.co/edit/IowesXE3ag6xOYfB6KrN?p=preview

I want to hide the textbox when the user clicks on 'Savings' link, display the box when clicking on 'Cost' link.


Solution

  • Every time you use ng-controller, you make a new instance of said controller, with it's own scope. If you set subCCtrl on the body tag (or a new parent), and remove it from the two divs it is currently on, it works for me.

    Other solutions you might want to look in to are by keeping "hideThisBox" on the root scope, broadcasting an event when clicking on save or by keeping it in a service.