-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
40 lines (32 loc) · 1.12 KB
/
app.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
//First we define our module
angular.module('steven', []);
/* From now forward `angular.module('steven')` will return our module and we can
attach controllers, services etc to it.
*/
angular.module('steven').controller('MainController', function($scope, $http) {
/*
functions defined on the scope are accessible to html event handler attributes, so an
element with onclick="removeSomething()" will cause this function to run on click
*/
$scope.removeSomething = function() {
$scope.sampleArray.pop();
};
$scope.addSomething = function() {
var max = Math.max(0, Math.max.apply(null, $scope.sampleArray));
$scope.sampleArray.push(max+1);
};
$scope.sampleArray = [1,2,3,4,5];
/*
Now let's load some stuff from reddit
You might also want to look at the docs for ngResource at
(https://docs.angularjs.org/api/ngResource/service/$resource)
ngResource simplifies talking to REST APIs
*/
$http({
method: 'GET',
url: 'http://api.reddit.com'
}).then(function(response){
$scope.redditArray = response.data.data.children;
console.log($scope.redditArray);
});
});