-
Notifications
You must be signed in to change notification settings - Fork 5
/
ngview.js
45 lines (40 loc) · 1009 Bytes
/
ngview.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
var app = angular.module('app', []);
app.config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'ngview.tmpl.html',
controller: 'ViewCtrl',
resolve: {
loadData: viewCtrl.loadData
}
})
.otherwise({
redirectTo:'/'
});
});
app.directive('error', function($rootScope) {
return {
restrict:'E',
template: '<div class="alert-box alert" ng-show="isError">Error!!!</div>',
link: function(scope) {
$rootScope.$on('$routeChangeError', function(event, current, previous, rejection) {
scope.isError = true;
});
}
}
});
app.controller('AppCtrl', function($rootScope) {
});
var viewCtrl = app.controller('ViewCtrl', function($scope, $route) {
console.log($route);
$scope.model = {
message: "This is my app!!"
}
});
viewCtrl.loadData = function ($q, $timeout) {
var defer = $q.defer();
$timeout(function() {
defer.reject("Your network is down");
}, 500);
return defer.promise;
}