Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2ea17d3

Browse files
committed
Adding mainController and $scope functionality
1 parent 17c55cc commit 2ea17d3

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

chirpApp.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,25 @@
33
//Adds a controller called 'main controller' that handles
44
//core functionality.
55

6-
76
var app = angular.module('chirpApp', []);
87

9-
app.controller('mainController', function(){
8+
9+
//We are invoking a '$scope' object while constructing our mainController,
10+
//$scope is the 'M' in 'MVC' i.e. it is the path between the 'View'
11+
//and the 'Controller' through whih we can pass data and functions
12+
app.controller('mainController', function($scope){
13+
//Next, attach a 'posts' array to store all the posts that are created
14+
$scope.posts = [];
15+
//Now, we tack on a 'newPost' to $scope to store meta on the post that's
16+
//being created, creating an object with the meta fields below
17+
$scope.newPost = {created_by: '', text: '', created_at: ''};
18+
19+
20+
//Here is a function that will add the contents of 'newPosts' to the 'posts'
21+
//array whenever the 'Tweet' button is pressed
22+
$scope.post = function(){
23+
$scope.newPost.created_at = Date.now();
24+
$scope.posts.push($scope.newPost);
25+
$scope.newPost = {created_by: '', text: '', created_at: ''};
26+
};
1027
});

0 commit comments

Comments
 (0)