Convert Figma logo to code with AI

johnpapa logoangular-styleguide

Angular Style Guide: A starting point for Angular development teams to provide consistency through good practices.

23,883
4,153
23,883
79

Top Related Projects

šŸŒ± [Deprecated] Extensible, reliable, modular, PWA ready starter project for Angular (2 and beyond) with statically typed build and AoT compilation

CLI tool for Angular

AngularJS styleguide for teams

95,657

Deliver web apps with confidence šŸš€

MFE Starter

13,536

The de-facto solution to flexible routing with nested views in AngularJS

Quick Overview

The Angular Style Guide by John Papa is a comprehensive set of best practices and coding conventions for developing Angular applications. It aims to provide consistency, maintainability, and scalability for Angular projects by offering opinionated guidelines on file naming, code structure, and architectural patterns.

Pros

  • Promotes consistent coding practices across teams and projects
  • Improves code readability and maintainability
  • Offers clear examples and explanations for each guideline
  • Regularly updated to align with the latest Angular versions

Cons

  • Some guidelines may be opinionated and not suit every project's needs
  • Can be overwhelming for beginners due to the extensive number of rules
  • May require additional setup time to implement all guidelines in existing projects
  • Some teams might find it challenging to adapt to all recommendations

Code Examples

This is not a code library, but rather a set of guidelines. Therefore, there are no code examples or getting started instructions to provide.

Competitor Comparisons

šŸŒ± [Deprecated] Extensible, reliable, modular, PWA ready starter project for Angular (2 and beyond) with statically typed build and AoT compilation

Pros of angular-seed

  • Provides a complete project structure and build setup for Angular applications
  • Includes testing configurations and tools out of the box
  • Offers a more comprehensive starting point for large-scale Angular projects

Cons of angular-seed

  • May be overwhelming for beginners or smaller projects
  • Requires more setup and configuration to get started
  • Less focused on specific coding style guidelines

Code Comparison

angular-styleguide (style recommendation):

/* Recommended */
function getCustomer() {
  return $http.get('/api/customer')
    .then(getCustomerComplete)
    .catch(getCustomerFailed);

  function getCustomerComplete(response) {
    return response.data;
  }

  function getCustomerFailed(error) {
    logger.error('XHR Failed for getCustomer.' + error.data);
  }
}

angular-seed (project structure):

ā”œā”€ā”€ src
ā”‚   ā”œā”€ā”€ client
ā”‚   ā”‚   ā”œā”€ā”€ app
ā”‚   ā”‚   ā”‚   ā”œā”€ā”€ about
ā”‚   ā”‚   ā”‚   ā”‚   ā”œā”€ā”€ about.component.html
ā”‚   ā”‚   ā”‚   ā”‚   ā”œā”€ā”€ about.component.ts
ā”‚   ā”‚   ā”‚   ā”‚   ā””ā”€ā”€ about.module.ts
ā”‚   ā”‚   ā”‚   ā”œā”€ā”€ home
ā”‚   ā”‚   ā”‚   ā”‚   ā”œā”€ā”€ home.component.html
ā”‚   ā”‚   ā”‚   ā”‚   ā”œā”€ā”€ home.component.ts
ā”‚   ā”‚   ā”‚   ā”‚   ā””ā”€ā”€ home.module.ts
ā”‚   ā”‚   ā”‚   ā”œā”€ā”€ app.component.html
ā”‚   ā”‚   ā”‚   ā”œā”€ā”€ app.component.ts
ā”‚   ā”‚   ā”‚   ā””ā”€ā”€ app.module.ts

While angular-styleguide focuses on providing coding style recommendations and best practices, angular-seed offers a complete project structure and build setup for Angular applications. The code comparison shows a style recommendation from angular-styleguide and a typical project structure from angular-seed.

CLI tool for Angular

Pros of Angular CLI

  • Provides a complete development environment with built-in tools for project creation, testing, and deployment
  • Offers automatic configuration and setup of Angular projects, reducing boilerplate code
  • Includes a powerful command-line interface for generating components, services, and other Angular artifacts

Cons of Angular CLI

  • Less focused on coding style and best practices compared to Angular Styleguide
  • May introduce unnecessary complexity for smaller projects or developers who prefer more manual control
  • Steeper learning curve for developers new to Angular or command-line tools

Code Comparison

Angular CLI (generating a component):

ng generate component my-component

Angular Styleguide (component naming convention):

export class MyComponentComponent { }

Key Differences

  • Angular CLI is a comprehensive toolset for Angular development, while Angular Styleguide focuses on coding conventions and best practices
  • Angular CLI automates many development tasks, whereas Angular Styleguide provides guidelines for manual implementation
  • Angular CLI is actively maintained by the Angular team, while Angular Styleguide is a community-driven project

Use Cases

  • Use Angular CLI for rapid development, project scaffolding, and streamlined workflows
  • Refer to Angular Styleguide for coding standards, naming conventions, and architectural patterns

Community and Support

  • Angular CLI has extensive official documentation and regular updates from the Angular team
  • Angular Styleguide benefits from community contributions and discussions around best practices

AngularJS styleguide for teams

Pros of angularjs-styleguide

  • More concise and easier to digest for beginners
  • Focuses specifically on AngularJS 1.x, making it ideal for legacy projects
  • Includes a section on TypeScript usage with AngularJS

Cons of angularjs-styleguide

  • Less comprehensive than angular-styleguide
  • Not actively maintained, with the last update in 2016
  • Lacks detailed explanations for some recommendations

Code Comparison

angular-styleguide:

angular
  .module('app', [])
  .controller('SomeController', SomeController);

function SomeController() {
  var vm = this;
  vm.name = 'John';
}

angularjs-styleguide:

function MainCtrl () {
  var vm = this;
  vm.name = 'John';
}

angular
  .module('app')
  .controller('MainCtrl', MainCtrl);

Both style guides recommend using the controllerAs syntax and assigning this to a variable named vm. However, angular-styleguide suggests defining the module and controller together, while angularjs-styleguide separates the function definition from the module declaration.

The angular-styleguide provides more detailed explanations and covers a broader range of topics, making it more suitable for larger projects and teams. On the other hand, angularjs-styleguide is more focused on AngularJS 1.x and may be preferable for developers working exclusively with that version.

95,657

Deliver web apps with confidence šŸš€

Pros of Angular

  • Official framework repository with full source code and documentation
  • Actively maintained with frequent updates and new features
  • Comprehensive tooling and CLI support for development

Cons of Angular

  • Larger codebase and steeper learning curve
  • More opinionated architecture, potentially less flexible for some use cases
  • Requires TypeScript knowledge for effective development

Code Comparison

Angular (component example):

@Component({
  selector: 'app-example',
  template: '<h1>{{ title }}</h1>'
})
export class ExampleComponent {
  title = 'Hello, Angular!';
}

Angular Styleguide (naming convention example):

/* avoid */
const getCustomerId = function() {};

/* recommended */
function getCustomerId() {}

Key Differences

  • Angular Styleguide focuses on best practices and coding standards, while Angular is the full framework implementation
  • Angular Styleguide provides guidelines for writing clean, maintainable Angular code, whereas Angular offers the actual runtime and development environment
  • Angular Styleguide is primarily a reference document, while Angular is a complete development ecosystem with tools, libraries, and runtime

Use Cases

  • Use Angular for building full-scale applications with the Angular framework
  • Refer to Angular Styleguide for best practices and coding conventions when working on Angular projects

MFE Starter

Pros of PatrickJS-starter

  • Provides a complete starter kit for Angular projects, including pre-configured tools and dependencies
  • Includes modern development features like server-side rendering and progressive web app support
  • Offers a more opinionated and structured approach to project setup

Cons of PatrickJS-starter

  • May be overwhelming for beginners due to its comprehensive nature
  • Less flexibility in terms of project structure and tooling choices
  • Requires more frequent updates to keep up with the latest Angular versions and best practices

Code Comparison

angular-styleguide focuses on coding style and best practices:

/* Recommended */
function getUser() {
  return this.http.get('api/users')
    .pipe(
      map((response: Response) => response.json())
    );
}

PatrickJS-starter provides a full project structure:

// src/app/app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';

@NgModule({
  imports: [BrowserModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent]
})
export class AppModule { }

Summary

angular-styleguide is a comprehensive style guide for Angular development, focusing on best practices and coding conventions. PatrickJS-starter, on the other hand, is a full-featured starter kit that provides a complete project setup with pre-configured tools and modern development features. While angular-styleguide offers more flexibility and is easier for beginners to adopt, PatrickJS-starter provides a more opinionated and structured approach to Angular project development.

13,536

The de-facto solution to flexible routing with nested views in AngularJS

Pros of ui-router

  • Provides a powerful state-based routing system for single-page applications
  • Offers nested views and multiple named views for complex UI structures
  • Supports URL routing, as well as abstract states for non-URL-based navigation

Cons of ui-router

  • Steeper learning curve compared to the simplicity of style guides
  • May introduce unnecessary complexity for smaller projects
  • Requires additional setup and configuration

Code Comparison

angular-styleguide (style recommendation):

angular
    .module('app')
    .controller('HomeController', HomeController);

function HomeController() {
    var vm = this;
    vm.title = 'Home';
}

ui-router (state configuration):

$stateProvider
    .state('home', {
        url: '/home',
        templateUrl: 'home.html',
        controller: 'HomeController',
        controllerAs: 'vm'
    });

Summary

While angular-styleguide focuses on best practices and coding conventions for Angular applications, ui-router is a specific routing solution. The style guide provides general recommendations for structuring and writing Angular code, whereas ui-router offers a robust routing mechanism for complex applications. The choice between them depends on the project's needs: ui-router for advanced routing capabilities, and angular-styleguide for overall code quality and consistency.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Angular Style Guide

Versions

There are multiple versions of Angular, and thus there are multiple versions of the guide. Choose your guide appropriately.

Angular 1 Style Guide

The Angular 1 Style Guide.

Angular 2 Style Guide

The Angular 2 Style Guide.

Angular Team Endorsed

Special thanks to Igor Minar, lead on the Angular team, for reviewing, contributing feedback, and entrusting me to shepherd this guide.

Purpose

Opinionated Angular style guide for teams by @john_papa

If you are looking for an opinionated style guide for syntax, conventions, and structuring Angular applications, then step right in. These styles are based on my development experience with Angular, presentations, Pluralsight training courses and working in teams.

The purpose of this style guide is to provide guidance on building Angular applications by showing the conventions I use and, more importantly, why I choose them.

If you like this guide, check out my Angular Patterns: Clean Code course at Pluralsight which is a companion to this guide.

Angular Patterns: Clean Code

Community Awesomeness and Credit

Never work in a vacuum. I find that the Angular community is an incredible group who are passionate about sharing experiences. Many of my styles have been from the many pair programming sessions Ward Bell and I have had. My most excellent friend Ward has helped influence the ultimate evolution of these guides.

Contributing

Open an issue first to discuss potential changes/additions. If you have questions with the guide, feel free to leave them as issues in the repository. If you find a typo, create a pull request. The idea is to keep the content up to date and use githubĆ¢Ā€Ā™s native feature to help tell the story with issues and PRĆ¢Ā€Ā™s, which are all searchable via google. Why? Because odds are if you have a question, someone else does too! You can learn more here at about how to contribute.

By contributing to this repository you are agreeing to make your content available subject to the license of this repository.

Process

1. Discuss the changes in a GitHub issue.
2. Open a Pull Request, reference the issue, and explain the change and why it adds value.
3. The Pull Request will be evaluated and either merged or declined.

License

tldr; Use this guide. Attributions are appreciated.

Copyright

Copyright (c) 2014-2016 John Papa

(The MIT License)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Back to top