-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathscript.js
More file actions
48 lines (43 loc) · 1.2 KB
/
script.js
File metadata and controls
48 lines (43 loc) · 1.2 KB
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
'use strict';
var redditApp = angular.module('reddit', ["ngRoute"])
.config(function($routeProvider) {
$routeProvider
.when('/', {
controller: 'ListCtrl',
templateUrl: 'list.html'
})
.when('/new', {
controller: 'NewLinkCtrl',
templateUrl: 'new.html'
})
.when('/show/:id', {
controller: 'showLinkCtrl',
templateUrl: 'show.html'
})
.otherwise({
redirectTo: '/'
})
})
.service('linkService', function() {
this.links = [
{ title: 'Google', url: 'http://google.com', description: 'The google thing' },
{ title: 'Bing', url: 'http://bing.com', description: 'Not a search engine' },
{ title: 'Yahoo', url: 'http://yahoo.com', description: 'The yahoo thing' }
];
this.storeLink = function(newLink) {
this.links.unshift(newLink);
};
this.deleteLink = function(linkIndex) {
this.links.splice(linkIndex, 1);
};
this.readLink = function(index) {
return this.links[index];
};
})
.controller('showLinkCtrl', function($scope, linkService, $routeParams){
$scope.oneLink = linkService.readLink($routeParams.id);
})
.controller('ListCtrl', function($scope, linkService){
$scope.links = linkService.links;
$scope.deleteLink = linkService.deleteLink;
});