https://github.com/normandy72/routing-state
Routing State with resolve in AngularJS. Coursera course "Single Page Web Applications with AngularJS" by Yaakov Chaikin.
https://github.com/normandy72/routing-state
angular angularjs css css3 html html5 javascript js
Last synced: about 1 month ago
JSON representation
Routing State with resolve in AngularJS. Coursera course "Single Page Web Applications with AngularJS" by Yaakov Chaikin.
- Host: GitHub
- URL: https://github.com/normandy72/routing-state
- Owner: Normandy72
- Created: 2023-01-22T17:14:07.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-01-22T17:43:42.000Z (over 3 years ago)
- Last Synced: 2025-01-14T12:46:22.536Z (over 1 year ago)
- Topics: angular, angularjs, css, css3, html, html5, javascript, js
- Language: JavaScript
- Homepage:
- Size: 92.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Routing State with resolve
### Step 1: Set up resolve Property
```
.state('view1', {
url: '/view1',
templateUrl: 'view1.html',
controller: 'ViewCtrl as view1',
resolve: {
myData: ['Service', function(Service){
return Service.getData();
}]
}
});
```
` myData` - return value is injected into View1Ctrl as 'myData'
### Step 2: Inject Resolve Property Into Controller
```
View1Ctrl.$inject = ['myData'];
function View1Ctrl(myData){
var view1 = this;
view1.myData = myData;
}
```
#### Resolve Properties Can Be Anything
```
.state('view1', {
url: '/view1',
templateUrl: 'view1.html',
controller: 'View1Ctrl as view1',
resolve: {
myData: 'some data'
}
});
```
***
#### _Summary_
* `resolve` property can be used to inject values directly into the controller responsible for the state.
* If `resolve` property is a promise
* router will wait for it to resolve before transitioning to the state;
* if rejected, router will not transition to the new state at all.
* The name of the key in the resolve's property object is what is to be injected into the corresponding controller's function.
* `resolve` can have properties that contain anything: objects, strings, etc.
***