I am working on my tutorial AngularUI project. I read all about states, nested states and abstract states. The problem is that I can't understand why and when I should use abstract state?
相关问题
- angularJS: ui-router equivalent to $location.searc
- Separate AngularJS Controllers Into Separate Files
- Angular ngAnimate not working first time on page l
- Ionic Spinner not showing up
- Upload file to Google Cloud Storage using AngularJ
相关文章
- Passing variable through URL with angular js
- Watch entire object (deep watch) with AngularJS
- Angular ng-if change span text
- Can ng-show directive be used with a delay
- AngularJS $routeParams vs $stateParams
- Multiple parameters in AngularJS $resource GET
- How to set class/style of accordion heading in Ang
- PUT to S3 with presigned url gives 403 error
Abstract states
There are situations where we need to have some common information available in several states. For this purpose UI-Router provides the possibility to specify abstract states. Abstract states can have child states but they can not be activated itself neither transitioned to. An abstract state is implicitly activated when one of its child states are activated. This is useful when: we need to prepend a url to all the child state urls we need to insert a template with its own ui-view that the child states will fill we need to provide resolved dependencies (via resolve) in order to be used by child states we need to provide inherited custom state data in order to be used by child states or events Abstract states are defined specifying the abstract key in the state configuration object set to true.
If you don't want a state that can be hit\transitioned to then you can make it an abstract state. Example
If you don't want the user to simply go to
\A
, you should make itabstract
.Basically, abstract states help you to move common functionality from different states into a parent abstract state.
A typical example is a state that handles the loading of user name, localization settings, meta data. You don't want the user to redirect to a state that will load just that. You want that to be loaded always, when redirected to every state
/session
would be abstract but/session/main
,/session/detail
would not. Through the dependencies, session data would be loaded when going to bothmain
anddetail
states but you don't want the user to go tosession
state.It gets called when we load its child's state. You can use abstract state to define some initial pattern of your page, suppose you can take an example of Any social media site, where you wanted to show user profile & social page. For that you could have one
abstract
state, which will haveurl: ""
& have basic layout of your page. Likeheader
,content
&footer
named views.header
&footer
named view will be filled up by the abstract state & then child will define the what the content is depends on which module is displayed./profile
will show theuserProfile.html
&/social
will show the social page of an usersocial.html
.Config
Other main feature of
abstract
is you can have common resolve on it, provide inherited custom data via data for use by child states or an event listener. Also you can haveOnEnter
&OnExit
on it to making sure things before loadingstate
& while leaving fromstate