On this page
AngularJS to Angular Concepts: Quick Reference
Angular is the name for the Angular of today and tomorrow. AngularJS is the name for all v1.x versions of Angular.
This guide helps you transition from AngularJS to Angular by mapping AngularJS syntax to the equivalent Angular syntax.
See the Angular syntax in this .
Template basics
Templates are the user-facing part of an Angular application and are written in HTML. The following table lists some of the key AngularJS template features with their equivalent Angular template syntax.
AngularJS | Angular |
---|---|
Bindings/interpolation In AngularJS, an expression in curly braces denotes one-way binding. This binds the value of the element to a property in the controller associated with this template. When using the |
Bindings/interpolation In Angular, a template expression in curly braces still denotes one-way binding. This binds the value of the element to a property of the component. The context of the binding is implied and is always the associated component, so it needs no reference variable. For more information, see the Interpolation section of the Template Syntax page. |
Filters To filter output in AngularJS templates, use the pipe character (|) and one or more filters. This example filters the |
Pipes In Angular you use similar syntax with the pipe (|) character to filter output, but now you call them pipes. Many (but not all) of the built-in filters from AngularJS are built-in pipes in Angular. For more information, see Filters/pipes below. |
Local variables Here, |
Input variables Angular has true template input variables that are explicitly defined using the For more information, see the ngFor micro-syntax section of the Template Syntax page. |
Template directives
AngularJS provides more than seventy built-in directives for templates. Many of them aren't needed in Angular because of its more capable and expressive binding system. The following are some of the key AngularJS built-in directives and their equivalents in Angular.
AngularJS | Angular |
---|---|
ng-app The application startup process is called bootstrapping. Although you can bootstrap an AngularJS app in code, many applications bootstrap declaratively with the |
Bootstrapping Angular doesn't have a bootstrap directive. To launch the app in code, explicitly bootstrap the application's root module ( |
ng-class In AngularJS, the In the first example, the You can specify multiple classes, as shown in the second example. |
ngClass In Angular, the In the first example, the You can specify multiple classes, as shown in the second example. Angular also has class binding, which is a good way to add or remove a single class, as shown in the third example. For more information see the Attribute, class, and style bindings section of the Template Syntax page. |
ng-click In AngularJS, the In the first example, when the user clicks the button, the The second example demonstrates passing in the |
Bind to the |
ng-controller In AngularJS, the |
Component decorator In Angular, the template no longer specifies its associated controller. Rather, the component specifies its associated template as part of the component class decorator. For more information, see Architecture Overview. |
ng-hideIn AngularJS, the |
Bind to the |
ng-href The In AngularJS, the Routing is handled differently in Angular. |
Bind to the |
ng-if In AngularJS, the In this example, the |
*ngIf The In this example, the The (*) before |
ng-model In AngularJS, the |
ngModel In Angular, two-way binding is denoted by For more information on two-way binding with |
ng-repeat In AngularJS, the In this example, the table row ( |
*ngFor The Notice the other syntax differences: The (*) before For more information, see Structural Directives. |
ng-show In AngularJS, the In this example, the |
Bind to the |
ng-src The |
Bind to the |
ng-style In AngularJS, the In the example, the |
ngStyle In Angular, the In the first example, the Angular also has style binding, which is good way to set a single style. This is shown in the second example. For more information on style binding, see the Style binding section of the Template Syntax page. For more information on the |
ng-switch In AngularJS, the In this example, if |
ngSwitch In Angular, the In this example, if The (*) before For more information, see The NgSwitch directives section of the Template Syntax page. |
Filters/pipes
Angular pipes provide formatting and transformation for data in the template, similar to AngularJS filters. Many of the built-in filters in AngularJS have corresponding pipes in Angular. For more information on pipes, see Pipes.
AngularJS | Angular |
---|---|
currency Formats a number as currency. |
currency The Angular |
date Formats a date to a string based on the requested format. |
date The Angular |
filter Selects a subset of items from the defined collection, based on the filter criteria. |
noneFor performance reasons, no comparable pipe exists in Angular. Do all your filtering in the component. If you need the same filtering code in several templates, consider building a custom pipe. |
json Converts a JavaScript object into a JSON string. This is useful for debugging. |
json The Angular |
limitTo Selects up to the first parameter (2) number of items from the collection starting (optionally) at the beginning index (0). |
slice The |
lowercase Converts the string to lowercase. |
lowercase The Angular |
number Formats a number as text. |
number The Angular Angular also has a |
orderBy Displays the collection in the order specified by the expression. In this example, the movie title orders the |
noneFor performance reasons, no comparable pipe exists in Angular. Instead, use component code to order or sort results. If you need the same ordering or sorting code in several templates, consider building a custom pipe. |
Modules/controllers/components
In both AngularJS and Angular, modules help you organize your application into cohesive blocks of functionality.
In AngularJS, you write the code that provides the model and the methods for the view in a controller. In Angular, you build a component.
Because much AngularJS code is in JavaScript, JavaScript code is shown in the AngularJS column. The Angular code is shown using TypeScript.
AngularJS | Angular |
---|---|
IIFE In AngularJS, an immediately invoked function expression (or IIFE) around controller code keeps it out of the global namespace. |
noneThis is a nonissue in Angular because ES 2015 modules handle the namespacing for you. For more information on modules, see the Modules section of the Architecture Overview. |
Angular modules In AngularJS, an Angular module keeps track of controllers, services, and other code. The second argument defines the list of other modules that this module depends upon. |
NgModules NgModules, defined with the For more information on modules, see NgModules. |
Controller registration AngularJS has code in each controller that looks up an appropriate Angular module and registers the controller with that module. The first argument is the controller name. The second argument defines the string names of all dependencies injected into this controller, and a reference to the controller function. |
Component decorator Angular adds a decorator to the component class to provide any required metadata. The This is how you associate a template with logic, which is defined in the component class. For more information, see the Components section of the Architecture Overview page. |
Controller function In AngularJS, you write the code for the model and methods in a controller function. |
Component class In Angular, you create a component class to contain the data model and control methods. Use the TypeScript For more information, see the Components section of the Architecture Overview page. |
Dependency injection In AngularJS, you pass in any dependencies as controller function arguments. This example injects a To guard against minification problems, tell Angular explicitly that it should inject an instance of the |
Dependency injection In Angular, you pass in dependencies as arguments to the component class constructor. This example injects a For more information, see the Dependency injection section of the Architecture Overview. |
Style sheets
Style sheets give your application a nice look. In AngularJS, you specify the style sheets for your entire application. As the application grows over time, the styles for the many parts of the application merge, which can cause unexpected results. In Angular, you can still define style sheets for your entire application. But now you can also encapsulate a style sheet within a specific component.
AngularJS | Angular |
---|---|
Link tag AngularJS, uses a |
Styles configuration With the Angular CLI, you can configure your global styles in the StyleUrlsIn Angular, you can use the This allows you to set appropriate styles for individual components that won’t leak into other parts of the application. |
© 2010–2020 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v8.angular.io/guide/ajs-quick-reference