Skip to content

Commit 6974a89

Browse files
committed
angularjs run and config functions
1 parent 78a02a9 commit 6974a89

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* Main configuration function.
3+
*/
4+
5+
(function () {
6+
'use strict';
7+
8+
angular.module('riccardo').config(config);
9+
10+
/**
11+
* @function config
12+
* @memberOf riccardo
13+
* @param $urlMatcherFactoryProvider
14+
* @param $urlRouterProvider
15+
* @param $stateProvider
16+
* @param $stateParamsProvider
17+
* @param $locationProvider
18+
* @description
19+
* - Define the states for the whole application (using `UI-Router`).
20+
* - Provide clean URL for the application.
21+
*/
22+
function config($urlMatcherFactoryProvider, $urlRouterProvider, $stateProvider, $stateParamsProvider, $locationProvider) {
23+
$urlMatcherFactoryProvider.caseInsensitive(true);
24+
$urlMatcherFactoryProvider.strictMode(false);
25+
26+
$urlRouterProvider.otherwise('/');
27+
28+
$stateProvider
29+
.state('riccardo', {
30+
abstract: true,
31+
views: {
32+
header: {},
33+
sidebar: {},
34+
content: {},
35+
detailsContent: {},
36+
footer: {}
37+
}
38+
})
39+
.state('riccardo-exercise', {
40+
url: '/',
41+
parent: 'riccardo',
42+
data: {
43+
pageTitle: 'People - Riccardo\'s Front End exercise'
44+
}
45+
})
46+
.state('person-details', {
47+
url: 'person-details/:id/:name',
48+
parent: 'riccardo-exercise',
49+
data: {
50+
pageTitle: 'Person Details - Riccardo\'s Front End exercise'
51+
},
52+
params: {
53+
id: $stateParamsProvider.id,
54+
person: $stateParamsProvider.person
55+
},
56+
views: {
57+
'!detailsContent': {
58+
component: 'person'
59+
}
60+
}
61+
});
62+
63+
$locationProvider.html5Mode(true);
64+
}
65+
}());

app/config-and-run/riccardo-run.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Run function.
3+
*/
4+
5+
(function () {
6+
'use strict';
7+
8+
angular.module('riccardo').run(run);
9+
10+
/**
11+
* @function run
12+
* @memberOf riccardo
13+
* @param $rootScope
14+
* @param $state
15+
* @param $stateParams
16+
* @param $trace
17+
*/
18+
function run($rootScope, $state, $stateParams, $trace) {
19+
/*************************/
20+
/*** Debug transitions ***/
21+
/*************************/
22+
// For debug purposes, uncomment this line and in the console there will be all the
23+
// states transitions
24+
// $trace.enable('TRANSITION');
25+
26+
/********************************************************************/
27+
/*** Set the `$state` available to the `$rootScope` ***/
28+
/*** With this trick we can have available the title of the pages ***/
29+
/********************************************************************/
30+
$rootScope.$state = $state;
31+
$rootScope.$stateParams = $stateParams;
32+
}
33+
}());

0 commit comments

Comments
 (0)