-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
90 lines (86 loc) · 3.71 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
angular.module('app', ['ui.router'])
.service('MyTimeoutService', function ($q, $timeout) {
var defer = $q.defer();
$timeout(function () {
defer.resolve('This is the promise value');
}, 1500);
return defer.promise;
})
.controller('TopController', function ($scope) {
// State Change Events
// https://github.com/angular-ui/ui-router/wiki
$scope.$on('$viewContentLoaded', function (event) {
console.log('View content loaded');
console.log(event);
});
console.log('top ->');
$scope.inheritMessage = 'I am the walrus and I still exist!';
})
.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
$urlRouterProvider.otherwise('/top/nest');
$stateProvider
.state('top', {
abstract: true,
url: '/top',
controller: 'TopController',
templateUrl: 'views/layout.html'
})
.state('top.nest', {
url: '/nest',
views: {
'list': {
template: '<ul><li>1</li><li>2</li></ul>'
},
'main': {
template: '<h1>Main View</h1>',
controller: function ($scope) {
console.log('top.nest main->');
console.log($scope.inheritMessage);
}
},
'': {
templateUrl: 'views/top.nest.unnamed.html'
}
}
})
.state('top.nest.edit', {
url: '/edit',
resolve: {
'myTimeoutResult': 'MyTimeoutService'
},
views: {
// to overwrite the state view 'main', we need to reference
// the 'owner' of the 'main' view.
// In this case it's the parent.
// https://github.com/angular-ui/ui-router/wiki/Multiple-Named-Views
// View Names - Relative vs. Absolute Names
'main@top': {
templateUrl: 'views/top.nest.edit.html',
controller: function ($scope, myTimeoutResult) {
console.log('top.nest.edit main->');
console.log($scope.inheritMessage);
console.log(myTimeoutResult);
}
}
// if we tried to just use 'main' to overwrite, it would not manage it
// as it would relatively look for a 'main' ui-view in this
// state's parent, which in this case is the nest view,
// which does not have a template.
}
})
.state('top.nest.edit.overwriteall', {
url: '/overwriteall',
views: {
// will target the unnamed view in the index.html
// Logically this state translates to '' + @ + ''.
// No name, the 'at sign', no name.
'@': {
template: '<h1>I have overwritten the whole top level view, even though I am nested many levels down. I do not inherit my scope from the parent scopes. Look at your console.</h1>',
controller: function ($scope) {
console.log('top.nest.edit.overwriteall ->')
console.log($scope.inheritMessage);
}
}
}
})
});