Is it possible to have multiple views [ https://github.com/angular-ui/ui-router/issues/494] using a singleton controller?
Use case: I have ui-view = header and ui-view = content. I change the title depending on the current state to display contextual relative buttons (e.g. go back, save, filter, etc.). I want these buttons to call a function in the content controller, but if I do the following, they will create two MyController objects. If there are any init functions, they are called twice, which in most cases doubles the requests to my server.
views:{ 'header':{ templateURL:'...', controller:'MyController' }, 'content':{ templateURL:'...', controller:'MyController' } }
Update: Based on @pankajparkar
My current index.html looks like this (simplified to understand)
<nav ui-view="header"></nav> <div ui-view="content"></div>
But your proposal will consist of / REQUIRE subviews
<!--index.html--> <body ui-view></body> <!--format.html--> <nav ui-view="header"></nav> <div ui-view="content"></div>
With the following controller
state('app', { url: '/app', controller: 'MyController', templateURL: 'format.html', //Targets ui-view in index.html views:{ 'header':{ templateURL:'...', //Targets ui-view="header" in format.html }, 'content':{ templateURL:'...', //Targets ui-view="header" in content.html } } });
angularjs angular-ui-router
Ryan h
source share