Skip to content

Instantly share code, notes, and snippets.

@pa4373
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pa4373/90574497998f3545d3c1 to your computer and use it in GitHub Desktop.
Save pa4373/90574497998f3545d3c1 to your computer and use it in GitHub Desktop.
Example angular.js coding style.
'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