angularjs - Create states from json file / http -
I have a backend that is generating a JSN file in which the information about the most important pages is in this json file I would like to load, and I want to create this state based on data in the file. I $ the state provider Or Can not inject into the constellor, and I can not inject $ http to .config, so I'm losing a bit.
The question is, how can I load a JSON file, go through the data and build states based on this data?
Quick editing: If there is a shortage in providing me with the necessary information, please tell me and I will try and improve the question.
I have tried to solve a similar problem and the UI-Router Xtra "states of the future Made it ". States of the future try to solve additional problems, such as RequireJS using sluggish loading, placeholders for full fluctuating modules, and fluctuating placeholders via bookmark url routing.
Demonstrate the use of future states for your use here:
I tried to use the stack overflow snippet runner, but there were problems, so it's non-code -Ronable Paste.
JS ::
// code here var app = angular Modules ("jsonstates", ["ct.ui.router.extras"]); App.config (['$ stateProvider', '$ futureStateProvider', function ($ sp, $ fsp) {var futureStateResolve = function ($ http) {return $ http.get ("states.json"). Response (angular.forEach (response.data, function (state) {$ sp.state (state);}}}} $ fsp.addResolve (futureStateResolve); console.log ($ fsp);}]); App .controller ("someCtrl", function () {}) HTML:
& lt;! DOCTYPE html> gt; & gt; & gt; Top & gt; Script data; security = "angular.js@1.2.25" data-save = "1.2.25" src = "https: //code.angularjs.org/1.2.25/angular.js "> gt; & lt; / script & gt; & lt; script src =" https://rawgit.com/angular-ui/ui-router/ 0.2.11 / release / angular-ui-router.js "& gt; & lt; / script & gt; & lt; script src =" ht Tps: //rawgit.com/christopherthielen/ui-router-extras/0.0.10/release/ct-ui-router-extras.js ">
Script & gt; Link rel =" Stylesheet "href =" style.css "/> & lt; Script src = "script.js" & gt; & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body ng-app = "jsonstates" & gt; & Lt; H1 & gt; Hello Plunker! & Lt; / H1> & Lt; A href = "# / top" & gt; Top State & lt; / A & gt; & Lt; A href = "# / top / nested" & gt; Nested state & lt; / A & gt; & Lt; Div ui-view & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt; Jason: [{"name": "top", "url": "/ up", "controller": "some Ctrl" , "Template": "& lt; h1 & gt; Top State & lt; / h1 & gt; & lt; div ui-view & gt; & lt; / div & gt; "Nested", "parent": "top", "url": "/ nested", "controller": "somewhat", "template": " nested state & lt
Comments
Post a Comment