angularjs - Get ui-router's ui-view to repopulate default content? -
How can I set the default content for a UI-router UI-view without a template?
I have something like this now:
& lt; Div ui-view & gt; Default content & lt; / Div & gt; Changes in states as
View update as expected, The problem is that I want to go back to the "Default" view:
$ urlRouterProvider .otherwise ('/');
.. "The default content" is no longer available. I think the template would be the easiest solution, but I need a default view to be indexable, is there a way to accomplish something like templates or HTML snapshots?
I do not know with default content ui-view
direct to recapitalization That's the way, but I've got an alternative solution that can help you: Save the contents of the ui-view
element in the compilation collection
I have a directive, which Written with the name uiView
, saves the template and it's time to create UI Router You need to touch HTML for T.
app.directive ('uiView', function ($ template catches) {return {restricted: 'EA', compiled: function (element) The {// template saves the contents of the UI-visible element with the $ template.Cache.put ('$ index.html', element.html ());}}}})
< P> You must also add a state for the point of the saved template ( $ index.html
), and mark it as the default state: A Pp.config (function ($ state Provider, $ urlRouterProvider) {$ stateProvider .state ("index", {url: '/', templateURL: '$ index.html' // dots saved template}) [...] // more states // Set 'index' as default state $ urlRouterProvider.otherwise ("/");})
Comments
Post a Comment