Difference between revisions of "AngularJS"
Karl Jones (Talk | contribs) (→Directive) |
Karl Jones (Talk | contribs) (→Component) |
||
Line 31: | Line 31: | ||
A component is a directive with added template features. | A component is a directive with added template features. | ||
− | + | See [[AngularJS component]]. | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
== Metadata == | == Metadata == |
Revision as of 13:05, 31 December 2016
In software development, AngularJS (commonly referred to as "Angular") is an open source web application JavaScript framework for developing single-page applications.
This article focuses on Angular 2.
Contents
Description
AngularJS simplifies both the development and the testing of web applications by providing a framework for client-side Model–view–controller (MVC) architecture, along with components commonly used in rich Internet applications.
AngularJS works by first reading the HTML page, which has embedded into it additional custom tag attributes.
Angular interprets those attributes as directives to bind input or output parts of the page to a model that is represented by standard JavaScript variables.
The values of those JavaScript variables can be manually set within the code, or retrieved from static or dynamic JSON resources.
Why Angular 2
- Keep and enhance best practices from Angular 2
- Standards: new syntax for templates binding to native DOM
- Improved change detection for speed/performance
- Reactive mechanism handling
- Immutable data objects
Directive
A directive is a class decorated with @Directive
.
See AngularJS directive.
Component
A component is a directive with added template features.
See AngularJS component.
Metadata
Metadata allows Angular to process (decorate) a class.
Attach metadata with Typescript using decorations.
Decorators are functions.
Most common is the @Component()
decorator.
Takes a config option with selector, template (Url), providers, directives, pipes and styles.
Templates
Template is HTML which tells Angular how to render a component.
Templates include data bindings as well as other components and directives.
Angular 2 leverages native DOM events and properties.
Angular 2 leverages shadow DOM, helps with view encapsulation (e.g. styles applied to component).
Best practice: put template in component metadata.
Data binding
Enables data to flow from component to template and vice-versa.
Includes interpolation, property binding, event binding, and two-way binding.
// string interpolation of property value {{value}} // bind to property from template [property]="value" // attach event listened to component (event)="handler" // two-way data binding "hot dog in a box" syntax [(ngModel)] = "property"
Services
A service is a class.
Handles business logic (so components don't have to).
Decorate with @Injectable
to inject dependencies into service.
Modules
See AngularJS module.
Dependency injection
See AngularJS dependency injection.
Class definitions
.Class({ constructor: function() {} });
Components
See AngularJS component.
Promises
Promises in AngularJS are provided by the built-in $q
service. They provide a way to execute asynchronous functions in series by registering them with a promise object.
Promises have made their way into native JavaScript as part of the ES6 specification. The angular $q service provides an interface that closely resembles this new API so porting code to ES6 should be easy.
See Promise object (JavaScript).
TreeView
See:
- Angular Treeview @ ngmodules.org
- AngularJS UI Tree @ github.io
- Is it possible to make a Tree View with Angular?
See also
External links
- Official website
- Quickstart
- Developer guide
- Introduction
- Conceptual overview
- Tutorial
- Angular code examples @ code.karljones.com
- AngularJS @ Wikipedia