{ "id": "guide/ajs-quick-reference", "title": "AngularJS to Angular concepts: Quick reference", "contents": "\n\n\n
Angular is the name for the Angular of today and tomorrow.\nAngularJS is the name for all v1.x versions of Angular.
\nThis guide helps you transition from AngularJS to Angular\nby mapping AngularJS syntax to the equivalent Angular syntax.
\nSee the Angular syntax in this
Templates are the user-facing part of an Angular application and are written in HTML.\nThe following table lists some of the key AngularJS template features with their equivalent Angular template syntax.
\n\n AngularJS\n | \n\n Angular\n | \n
---|---|
\nBindings/interpolationlink\nIn AngularJS, an expression in curly braces denotes one-way binding.\nThis binds the value of the element to a property in the controller\nassociated with this template. \n When using the | \n \nBindings/interpolationlink\n In Angular, a template expression in curly braces still denotes one-way binding.\nThis binds the value of the element to a property of the component.\nThe context of the binding is implied and is always the\nassociated component, so it needs no reference variable. \nFor more information, see the Interpolation guide. \n | \n
\nFilterslink\nTo filter output in AngularJS templates, use the pipe character (|) and one or more filters. \n This example filters the | \n \nPipeslink\n In Angular you use similar syntax with the pipe (|) character to filter output, but now you call them pipes.\nMany (but not all) of the built-in filters from AngularJS are\nbuilt-in pipes in Angular. \nFor more information, see Filters/pipes below. \n | \n
\nLocal variableslink\n Here, | \n \nInput variableslink\n Angular has true template input variables that are explicitly defined using the For more information, see the Structural directive shorthand section of Structural Directives. \n | \n
AngularJS provides more than seventy built-in directives for templates.\nMany of them aren't needed in Angular because of its more capable and expressive binding system.\nThe following are some of the key AngularJS built-in directives and their equivalents in Angular.
\n\n AngularJS\n | \n\n Angular\n | \n
---|---|
\nng-applink\nThe application startup process is called bootstrapping. \n Although you can bootstrap an AngularJS app in code,\nmany applications bootstrap declaratively with the | \n \nBootstrappinglink\n Angular doesn't have a bootstrap directive.\nTo launch the app in code, explicitly bootstrap the application's root module ( | \n
\nng-classlink\n In AngularJS, the In the first example, the You can specify multiple classes, as shown in the second example. \n | \n \nngClasslink\n In Angular, the In the first example, the You can specify multiple classes, as shown in the second example. \nAngular also has class binding, which is a good way to add or remove a single class,\nas shown in the third example. \nFor more information see Attribute, class, and style bindings page. \n | \n
\nng-clicklink\n In AngularJS, the In the first example, when the user clicks the button, the The second example demonstrates passing in the | \n \nBind to the \n | \n
\nng-controllerlink\n In AngularJS, the | \n \nComponent decoratorlink\n In Angular, the template no longer specifies its associated controller.\nRather, the component specifies its associated template as part of the component class decorator. \nFor more information, see Architecture Overview. \n | \n
\nng-hidelink\n In AngularJS, the | \n \nBind to the \n | \n
\nng-hreflink\n The In AngularJS, the Routing is handled differently in Angular. \n | \n \nBind to the \n | \n
\nng-iflink\n In AngularJS, the In this example, the | \n \n*ngIflink\n The In this example, the The (*) before | \n
\nng-modellink\n In AngularJS, the | \n \nngModellink\n In Angular, two-way binding is denoted by For more information on two-way binding with | \n
\nng-repeatlink\n In AngularJS, the In this example, the table row ( | \n \n*ngForlink\n The Notice the other syntax differences:\nThe (*) before For more information, see Structural Directives. \n | \n
\nng-showlink\n In AngularJS, the In this example, the | \n \nBind to the \n | \n
\nng-srclink\n The | \n \nBind to the \n | \n
\nng-stylelink\n In AngularJS, the In the example, the | \n \nngStylelink\n 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. \nFor more information on style binding, see the Style binding section of the\nAttribute binding page. \n For more information on the | \n
\nng-switchlink\n In AngularJS, the In this example, if | \n \nngSwitchlink\n In Angular, the In this example, if The (*) before For more information, see The NgSwitch directives\nsection of the Built-in directives page. \n | \n
Angular pipes provide formatting and transformation for data in the template, similar to AngularJS filters.\nMany of the built-in filters in AngularJS have corresponding pipes in Angular.\nFor more information on pipes, see Pipes.
\n\n AngularJS\n | \n\n Angular\n | \n
---|---|
\ncurrencylink\nFormats a number as currency. \n | \n \ncurrencylink\n The Angular | \n
\ndatelink\nFormats a date to a string based on the requested format. \n | \n \ndatelink\n The Angular | \n
\nfilterlink\nSelects a subset of items from the defined collection, based on the filter criteria. \n | \n \nnonelink\nFor 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. \n | \n
\njsonlink\nConverts a JavaScript object into a JSON string. This is useful for debugging. \n | \n \njsonlink\n The Angular | \n
\nlimitTolink\nSelects up to the first parameter (2) number of items from the collection\nstarting (optionally) at the beginning index (0). \n | \n \nslicelink\n The | \n
\nlowercaselink\nConverts the string to lowercase. \n | \n \nlowercaselink\n The Angular | \n
\nnumberlink\nFormats a number as text. \n | \n \nnumberlink\n The Angular Angular also has a | \n
\norderBylink\n Displays the collection in the order specified by the expression.\nIn this example, the movie title orders the | \n \nnonelink\nFor performance reasons, no comparable pipe exists in Angular.\nInstead, 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. \n | \n
In both AngularJS and Angular, modules help you organize your application into cohesive blocks of functionality.
\nIn AngularJS, you write the code that provides the model and the methods for the view in a controller.\nIn Angular, you build a component.
\nBecause much AngularJS code is in JavaScript, JavaScript code is shown in the AngularJS column.\nThe Angular code is shown using TypeScript.
\n\n AngularJS\n | \n\n Angular\n | \n
---|---|
\nIIFElink\nIn AngularJS, an immediately invoked function expression (or IIFE) around controller code\nkeeps it out of the global namespace. \n | \n \nnonelink\nThis is a nonissue in Angular because ES 2015 modules\nhandle the namespacing for you. \nFor more information on modules, see the Modules section of the\nArchitecture Overview. \n | \n
\nAngular moduleslink\nIn AngularJS, an Angular module keeps track of controllers, services, and other code.\nThe second argument defines the list of other modules that this module depends upon. \n | \n \nNgModuleslink\n NgModules, defined with the For more information on modules, see NgModules. \n | \n
\nController registrationlink\nAngularJS has code in each controller that looks up an appropriate Angular module\nand registers the controller with that module. \nThe first argument is the controller name. The second argument defines the string names of\nall dependencies injected into this controller, and a reference to the controller function. \n | \n \nComponent decoratorlink\n Angular adds a decorator to the component class to provide any required metadata.\nThe This is how you associate a template with logic, which is defined in the component class. \nFor more information, see the Components\nsection of the Architecture Overview page. \n | \n
\nController functionlink\nIn AngularJS, you write the code for the model and methods in a controller function. \n | \n \nComponent classlink\n In Angular, you create a component class to contain the data model and control methods. Use the TypeScript For more information, see the Components\nsection of the Architecture Overview page. \n | \n
\nDependency injectionlink\n In AngularJS, you pass in any dependencies as controller function arguments.\nThis example injects a To guard against minification problems, tell Angular explicitly\nthat it should inject an instance of the | \n \nDependency injectionlink\n In Angular, you pass in dependencies as arguments to the component class constructor.\nThis example injects a For more information, see the Dependency injection\nsection of the Architecture Overview. \n | \n
Style sheets give your application a nice look.\nIn AngularJS, you specify the style sheets for your entire application.\nAs the application grows over time, the styles for the many parts of the application\nmerge, which can cause unexpected results.\nIn Angular, you can still define style sheets for your entire application. But now you can\nalso encapsulate a style sheet within a specific component.
\n\n AngularJS\n | \n\n Angular\n | \n
---|---|
\nLink taglink\n AngularJS, uses a | \n \nStyles configurationlink\n With the Angular CLI, you can configure your global styles in the StyleUrlslink\n In Angular, you can use the This allows you to set appropriate styles for individual components that won’t leak into\nother parts of the application. \n | \n