angularjs
Skill15 starsChanged 9 months agoMITView on GitHub
Google's official AngularJS style guide. Covers controllers, services, directives, modules, dependency injection, and AngularJS 1.x best practices.
In this repository17 other files it gives its agents.
- common-lispSkill
- cppSkill
- csharpSkill
- goSkill
- html-cssSkill
- javascriptSkill
- javaSkill
- jsonSkill
- markdownSkill
- objective-cSkill
- pythonSkill
- rSkill
- shellSkill
- google-styleguides-skillsSkill
- swiftSkill
- typescriptSkill
- vim-scriptSkill
The file
Files
Google AngularJS Style Guide
Official Google AngularJS coding standards for consistent Angular 1.x applications.
Note: This guide covers AngularJS (Angular 1.x). For modern Angular (2+), see the Angular style guide.
Golden Rules
- One component per file — easier to maintain and test
- Use controllerAs syntax — avoid
$scopewhen possible - Services for business logic — keep controllers thin
- Explicit dependency injection — array annotation or
$inject - Modular structure — organize by feature, not type
- Use directives — for DOM manipulation only
- Avoid
$rootScope— use services for shared state
Quick Reference
Naming Conventions
| Element | Convention | Example |
| Modules | lowerCamelCase | myApp, myApp.users |
| Controllers | UpperCamelCase + Ctrl | UserCtrl, HomeCtrl |
| Services/Factories | UpperCamelCase | UserService, AuthFactory |
| Directives | lowerCamelCase | myDirective, userCard |
| Filters | lowerCamelCase | dateFormat, currencyDisplay |
| Files | feature.type.js | user.controller.js |
Controllers
// ✓ CORRECT - controllerAs syntax
angular.module('myApp')
.controller('UserCtrl', UserCtrl);
UserCtrl.$inject = ['UserService', '$log'];
function UserCtrl(UserService, $log) {
var vm = this; // vm = viewModel
vm.users = [];
vm.loadUsers = loadUsers;
activate();
function activate() {
loadUsers();
}
function loadUsers() {
return UserService.getAll()
.then(function(users) {
vm.users = users;
return vm.users;
});
}
}Services
// ✓ CORRECT - service for business logic
angular.module('myApp')
.factory('UserService', UserService);
UserService.$inject = ['$http', '$log'];
function UserService($http, $log) {
var service = {
getAll: getAll,
getById: getById,
create: create
};
return service;
function getAll() {
return $http.get('/api/users')
.then(function(response) {
return response.data;
});
}
function getById(id) {
return $http.get('/api/users/' + id)
.then(function(response) {
return response.data;
});
}
function create(user) {
return $http.post('/api/users', user);
}
}Directives
// ✓ CORRECT - directive for DOM manipulation
angular.module('myApp')
.directive('userCard', userCard);
function userCard() {
return {
restrict: 'E',
scope: {
user: '=',
onSelect: '&'
},
templateUrl: 'user-card.html',
controller: 'UserCardCtrl',
controllerAs: 'vm',
bindToController: true
};
}Dependency Injection
// ✓ CORRECT - explicit $inject annotation (minification-safe)
MyCtrl.$inject = ['$scope', '$http', 'UserService'];
function MyCtrl($scope, $http, UserService) {
// ...
}
// ✗ INCORRECT - inline array (verbose) or no annotation (breaks minification)
angular.module('myApp').controller('MyCtrl', ['$scope', function($scope) {}]);Modules
// ✓ CORRECT - one module definition per file
// app.module.js
angular.module('myApp', ['ngRoute', 'myApp.users', 'myApp.auth']);
// users/users.module.js
angular.module('myApp.users', []);
// ✗ INCORRECT - defining everything in one file
angular.module('myApp', []).controller(...).service(...).directive(...);Templates
<!-- ✓ CORRECT - controllerAs in template -->
<div ng-controller="UserCtrl as vm">
<h1>{{ vm.title }}</h1>
<ul>
<li ng-repeat="user in vm.users track by user.id">
{{ user.name }}
</li>
</ul>
<button ng-click="vm.loadUsers()">Reload</button>
</div>Common Mistakes
| Mistake | Correct Approach |
| Business logic in controllers | Move to services/factories |
Using $scope directly | Use controllerAs with vm alias |
| Implicit DI (breaks minification) | Use $inject or array annotation |
| DOM manipulation in controllers | Use directives |
| Everything in one module | Organize by feature into sub-modules |
Using $rootScope for shared state | Use a service instead |
| Watchers for every change | Use one-time binding :: where possible |
When to Use This Guide
- Maintaining AngularJS 1.x applications
- Code reviews for legacy Angular projects
- Onboarding new team members to AngularJS projects
Install
npx skills add testdino-hq/google-styleguides-skills/angularjsFull Guide
See angularjs.md for complete details, examples, and edge cases.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

