Last active
August 29, 2015 14:10
-
-
Save pa4373/90574497998f3545d3c1 to your computer and use it in GitHub Desktop.
Example angular.js coding style.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/** | |
* @ngdoc function | |
* @name ntuconnectAngularApp.controller:MeetupCtrl | |
* @description | |
* # MeetupCtrl | |
* Controller of the ntuconnectAngularApp | |
*/ | |
angular.module('ntuconnectAngularApp') | |
.controller('MeetupCtrl', ['$http', '$scope', function ($http, $scope) { | |
// Remember there's exactly one whitespace between function keyword and pairs of arguments, | |
// and another between pairs and opening bracket. Among the pair, three's one whitespace after the comma. | |
// declare local variables with values and functions, which might be used in the latter program. | |
var a = 7, | |
b = c, | |
d = function (e) { | |
console.log(e); | |
}; | |
// declare variables with values and functions under the $scope object. | |
$scope.people = [ | |
{ name: "John" } | |
]; | |
$scope.submit = function (e) { | |
$scope.people.push({name: e}); | |
}; | |
$scope.count = $scope.person.length; | |
// If you codes didn't return values, put them in this anonymous function. | |
// You might think it as the controller' main function. | |
(function () { | |
$http.get(API_URL, $scope.people).success(function (data) { | |
$scope.people = data; | |
}); | |
})(); | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment