File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change 3
3
//Adds a controller called 'main controller' that handles
4
4
//core functionality.
5
5
6
-
7
6
var app = angular . module ( 'chirpApp' , [ ] ) ;
8
7
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
+ } ;
10
27
} ) ;
You can’t perform that action at this time.
0 commit comments