-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
56 lines (46 loc) · 1.19 KB
/
Copy pathapp.js
File metadata and controls
56 lines (46 loc) · 1.19 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
49
50
51
52
53
54
55
56
(function() {
'use strict';
angular
.module('flapperNews', ['ui.router'])
.config(['$stateProvider', '$urlRouterProvider', ConfigFunction])
.controller('MainCtrl', ['$scope', 'postsService', MainCtrl])
.factory('postsService', [PostsService])
function ConfigFunction($stateProvider, $urlRouterProvider) {
$stateProvider
.state('/home', {
url: '/home',
templateUrl: '/home.html',
controller: 'MainCtrl',
controllerAs: 'mainCtrl'
})
}
function MainCtrl($scope, postsService) {
var vm = this
vm.posts = postsService.posts
vm.addPost = function() {
if (!vm.title) return
vm.posts.push({
title: vm.title,
link: vm.link,
upvotes: 0
})
vm.title = ''
vm.link = ''
}
vm.incrementUpvotes = function(post) {
post.upvotes++
}
}
function PostsService() {
var posts = [
{ title: 'post 1', upvotes: 5 },
{ title: 'post 2', upvotes: 2 },
{ title: 'post 3', upvotes: 15 },
{ title: 'post 4', upvotes: 9 },
{ title: 'post 5', upvotes: 4 }
]
return {
posts: posts
}
}
}());