Dart (https://www.dartlang.org/) is a general-purpose programming language to build web, server, IoT and mobile applications.
AngularDart (https://webdev.dartlang.org/angular) - also called Angular 2 for Dart or simply Angular - is a web app framework that focuses on productivity, performance, and stability. Hundreds of Google engineers use AngularDart to build the sophisticated, mission-critical apps that bring in much of Google’s revenue.
Dart and AngularDart significantly increase the productivity of the developers.
Slides from following meetup
https://www.meetup.com/Luxembourg-Dart-Lang-Meetup/events/237781037/
4. ANGULAR DART - INTRODUCTION
ANGULAR DART: ORIGINS
▸ Open Source Software under a MIT license
▸ Mainly developed by Google engineers
▸ Pitfall and best practices from AngularJS 1.x
▸ AngularDart 1.5 was the sandbox for AngularJS/Dart 2.x
▸ AngularDart 2.x now
5. ANGULAR DART - INTRODUCTION
ANGULAR DART: GOALS
▸ Help developers build
▸ Web Applications
▸ Productivity
▸ Write less code
Google teams report 2x productivity
▸ Performance
▸ Stability
7. ANGULAR DART - GETTING STARTED
INSTALL ANGULAR DART ON YOUR FAVORITE PLATFORM
▸ Install Dart on MacOS, Linux Ubuntu/Debian, Windows
▸ Install an IDE
▸ Recommended: WebStorm
▸ Dart Plugins available for
▸ Atom, Sublime Text 3, Visual Studio Code, Emacs, Vim
13. ANGULAR DART - OVERVIEW
MODULE
▸ Module refers to a Dart compilation unit
▸ Library (i.e. set of files in your application package)
▸ If Dart file has no library or part directive, then that file itself is a library
▸ Package (i.e. shared set of libraries)
▸ e.g. angular2, angular2_components packages
14. ANGULAR DART - OVERVIEW
METADATA / ANNOTATION / DECORATOR
▸ Metadata refers to a Dart metadata annotation
▸ Begins with the character @
▸ Followed by either a reference to
▸ a compile-time constant such as
Component, Directive, Input, Output…
▸ or a call to a constant constructor
▸ Metadata tells Angular how to process the annotated item
15. ANGULAR DART - OVERVIEW
DIRECTIVE
▸ Template are dynamic. Angular transforms the DOM
according to the instructions given by directives
▸ Directive is a Dart class with @Directive annotation
▸ There are three kinds of directives in Angular:
▸ Components with @Component annotation are building blocks of an Angular
application
▸ Attribute directives change the appearance or behaviour of a DOM element
▸ Structural directives alter layout by adding, removing, and replacing elements in DOM
16. ANGULAR DART - OVERVIEW
VIEW
▸ View is a portion of the screen that
▸ Displays information
▸ Responds to user actions such as clicks, mouse moves and keystrokes
▸ Contains other views
▸ Angular renders a view under the control of one or more Directives
▸ Often convenient to refer to a Component as a View
▸ Any Views might be loaded and unloaded dynamically
▸ Typically under the control of a router
17. ANGULAR DART - OVERVIEW
COMPONENT
▸ Directive with an embedded view are called Component
▸ Component is a Dart class with @Component annotation
▸ So it’s a dart class responsible for
▸ Exposing data to a view
▸ Handling most of the view’s display
▸ Handling user-interaction logic
▸ Can be built with input parameters identified with @Input annotation on property type
▸ Can emit event identified with @Output annotation on event’s property
▸ Similar to “controller” or “view-model” in MVC / MVVM design pattern
18. ANGULAR DART - OVERVIEW
TEMPLATE
▸ Template is a chunk of HTML that includes
▸ Data bindings
▸ Directives
▸ Other Components
19. ANGULAR DART - OVERVIEW
DATA BINDING
▸ Data binding enables
▸ Data to flow from
Component to DOM and vice-versa
▸ Possible data bindings are
▸ Interpolation
▸ Property / Event / Attribute / Class / Style binding
▸ Two-way data binding
20. ANGULAR DART - OVERVIEW
SERVICE
▸ Service is a class with a focused purpose
▸ Separates data and/or logic from Views or Components
▸ Encapsulates any value, function, or feature that your application needs
▸ e.g. logging service, data service, application configuration…
21. ANGULAR DART - OVERVIEW
DEPENDANCY INJECTION (DI)
▸ Supplies instance of a class with fully-formed “dependencies”
▸ A Provider is a recipe for creating new instances of a “dependency”
▸ An Injector maintains a cache of previously created service instances
▸ To use DI, register the Provider’s “dependency”
▸ when bootstrapping the Application
▸ or in the Component metadata
22. ANGULAR DART - OVERVIEW
BOOTSTRAPPING
▸ Bootstrapping consists on
▸ An application's top level "root" Component
i.e. first Component that is loaded for the application
by convention, AppComponent
▸ and optionally registers service Providers with DI
30. ANGULAR DART - TEMPLATE
DATA BINDING - STRINGS
▸ Binds text content to an interpolated string expression
(e.g. function, property, methods…)
▸ <p>Hello {{expression}}</p>
▸ Binds a property to an interpolated string expression
▸ <div title="Hello {{expression}}">
▸ Equivalent to <div [title]="'Hello' + expression">
31. ANGULAR DART - TEMPLATE
DATA BINDING - PROPERTY / ATTRIBUTE / CLASS / STYLE
▸ Binds property value to the result of expression
▸ <input [value]=“expression">
▸ Binds attribute role to the result of expression
▸ <div [attr.role]="expression">
▸ Binds the presence of the CSS class my-class on the element to the truthiness of the expression
▸ <div [class.my-class]="expression">
▸ Binds style property width to the result of expression expression in pixels. Units are optional.
▸ <div [style.width.px]="expression">
32. ANGULAR DART - TEMPLATE
DATA BINDING - EVENTS / TWO-WAY DATA BINDING
▸ Calls method onClick when a click event is triggered on this button element (or its
children) and passes in the event object.
▸ <button (click)=“onClick($event)">
▸ Sets up two-way data binding.
▸ <my-cmp [(title)]="name">
▸ Equivalent to <my-cmp [title]="name" (titleChange)="name=$event">
33. ANGULAR DART - TEMPLATE
DATA BINDING - STRUCTURE
▸ Creates a local variable movieplayer that provides access to the video element instance in data-
binding and event-binding expressions in the current template.
▸ <video #movieplayer ...>
<button (click)="movieplayer.play()">
</video>
▸ The * symbol turns the current element into an embedded template.
▸ <p *myUnless="myExpression">...</p>
▸ Equivalent to <template [myUnless]=“myExpression"><p>...</p></template>
▸ Used by builtin directives such as ngIf, ngFor
34. ANGULAR DART - TEMPLATE
BUILTIN DIRECTIVES - NGIF / NGFOR
▸ Available using platform_directives in pubspec.yaml
▸ transformers:
- angular2:
platform_directives:
- 'package:angular2/common.dart#COMMON_DIRECTIVES'
▸ Removes or recreates a portion of the DOM tree based on the expression.
▸ <section *ngIf="expression">
▸ Turns the li element and its contents into a template, and uses that to instantiate a view for each item in list.
▸ <li *ngFor="#item of list">
▸ <li *ngFor="let item of list">
▸ Others builtin directives ngSwitch, ngClass, ngStyle, ngTemplateOutlet
36. ANGULAR DART - COMPONENT LIFECYCLE HOOKS
GOALS
▸ Allow us to perform custom logic at various stages of a component's life
▸ Data isn't always immediately available in the constructor
▸ Implemented as class methods on the Component class
37. ANGULAR DART - COMPONENT LIFECYCLE HOOKS
LIFECYCLE HOOKS METHODS
▸ ngOnChanges()
Called after every change to input properties and
before processing content or child views.
▸ ngOnInit()
Called after the constructor, initialising input
properties, and after the first call to ngOnChanges.
▸ ngOnDestroy()
Called once, before the instance is destroyed.
▸ ngDoCheck()
Called every time that the input properties of a
component or a directive are checked.
Use it to extend change detection by performing a
custom check.
▸ ngAfterContentInit()
Called after ngOnInit when the component's or
directive's content has been initialized.
▸ ngAfterContentChecked()
Called after every check of the component's or directive's
content.
▸ ngAfterViewInit()
Called after ngAfterContentInit when the component's
view has been initialized. Applies to components only.
▸ ngAfterViewChecked()
Called after every check of the component's view.
Applies to components only.