json - Ionic - Adding states dynamically -
i developing mobile application using ionic framework. json
file containing template , it's controller. server push data once there's data in json
format. problem adding states dynamically, , have read it's possible @ config time.
please tell me if there's way through controller responsible of receiving , setting new state , receive json
, create new state.
the highly appreciated!
edit
i have found ui-router-extras (http://christopherthielen.github.io/ui-router-extras/#/future), don't know how make work application.
suppose controller gets json using $http json
looks like:
{ 'name':'preview', 'template':'<h1>hello</h2>' }
how add state in controller?
there simliar q & a:
- angularjs - ui-router - how configure dynamic views - answer
- start angular.js route-segment or ui-router after translations loaded
- angular - dynamically choose starting state
which shows, ui-router shipped great feature:
$urlrouterprovider.deferintercept(defer)
disables (or enables) deferring location change interception.
if wish customize behavior of syncing url (for example, if wish defer transition maintain current url), call method @ configuration time. then, @ run time, call
$urlrouter.listen()
after have configured own$locationchangesuccess
event handler.
there working plunkers here or here,
showing in .config()
phase stop url router:
.config(['$stateprovider', '$urlrouterprovider', function ($stateprovider, $urlrouterprovider) { // states, know beginning // declared "statically" $stateprovider ... // here stop $urlrouterprovider.deferintercept(); } ])
later, in .run()
phase, 1) configure states via $http 2) enable url routing
.run(['$urlrouter', '$timeout', '$state', function($urlrouter, $timeout, $state) { $http .get("modules.json") .success(function(data) { // here can use json configure $stateprovider // in example can use $timeout simulate $timeout(function(){ // here turn on again... $urlrouter.sync(); $urlrouter.listen(); // there decision, driven $http load // use state default target $state.go("parent.child"); }, 1000) ...
Comments
Post a Comment