I want to solve some value before loading the first page of my application, but this is telling me
Unknown Provider: programClassSummaryProvider & lt; - programClassSummary & lt; - HomeCtrl
I'm pretty sure I did it correctly, because I did the same for any other controller and route. But it is not working for my homepage controller It seems that it gets resolved in routing before loading the controller first. Anything wrong with my code
in routing.js
$ stateProvider .state ('home', {url: ?? '/ home', administrator: 'HomeCtrl Resolve: 'program_main.html', 'control', 'vm', templateUrl: 'index_main.html',: {programClassSummary: ['GroupDataFactory', function (groupDf) {return groupDf.getProgramClassSummary ();}]}, ncyBreadcrumb: {Skip: true }});
administrator.js
angular Module ('issMccApp'). Controller ('Homecuts', Homecrol); HomeCtrl $ Injection = ['$ scope', '$ location', '$ state', '$ auth', 'programClassSummary']; / * @ngInject * / function homeCtrl ($ radius, $ location, $ state, $ auth, programClassSummary) {var vm = this; Vm.isAuthenticated = isAuthor; Vm.programClassSummary = programClassSummary; If (! $ Auth.isAuthenticated ()) {$ state.go ('Login'); Return; } Function isAuthenticated () {$ auth.isAuthenticated (); }}
in factory.js
function getProgramClassSummary (showAll) {var query = ""; If (showAll) query = APIConfigObj.base_url + '/ api / group / infor / programclasssummary? All = 1 '; Else query = APIConfigObj.base_url + '/ api / group / infor / programclasssummary'; Return $ http.get (query) .success (function) {return result;}) .error (function) {return err;}}}
I would say, we really have to separate the world from the UI-Router
state, and angular itself. The reason clearly is clearly defined here (removed from) :
resolution (invention, local , Parents, themselves)
A set of ink solutions is an invocable task that can be implemented through
$ injector.invoke ()
, And there may be an official number dependency. An invention can either return a value directly, or$ q
promises if a promise is returned, it will be resolved and the resulting value will be used instead. The dependencies of the invocables are solved (in this order of superiority)
- Specified local people
- From another invocable that is part of this $ resolution call
- From an inventive who inherited the original parent from $ (or recursive
- from a previous $ resolution of that parent).
, which is this index.html
& lt; Body ng-controller = "RootCtrl" & gt; Uses a summary for the root: & lt; Pre & gt; {{Summary}} & lt; / Pre & gt; & Lt; Ul & gt; & Lt; Li & gt; & Lt; A href = "# / home" & gt; Home & lt; / A & gt; & Lt; Li & gt; & Lt; A href = "# / other" & gt; Other & lt; / A & gt; & Lt; / Ul & gt; & Lt; Div ui-view = "" & gt; & Lt; / Div & gt;
So, here we use a few RootCtrl
, which will not go through the state machine UI-router, this is the angular basic stuff
should be defined as root controller
.controller ('RootCtrl', ['$ scope', 'GroupDataFactory', function ($ scope, groupDf) {$ scope. Summary = groupDf.getProgramClassSummary ();}]]
For a state's home, we can use different approaches, in fact above (simple version below)
state ('home', {url: "/ house", templa Solution: {programClassSummary: ['GroupDataFactory', function (groupDf) {return groupDf.getProgramClassSummary ();}]}, controller: 'homecuton',})
< / Pre>and its controllers can now local
.controller ('HomeCtrl', ['$ scope', 'programClassSummary', function ($ scope, Summary) {$ scope.summaryForHome = summary;}]
chuck it in
No comments:
Post a Comment