Professional Documents
Culture Documents
Produced by
• What is Angular?
• Getting Started with Angular
• Demo: Setting Up the Angular Starter Application
• Component Classes and Template Variables
• Demo: Add a Header to the Application
• Working with an Array of Data
• Demo: Displaying a List of Colors
• Collecting Data from the User
• Demo: Add a New Color Form
• External Templates
• Demo: Moving the Template to an External File
• Styling a Component
• Demo: Adding Styles to the Component
• Keyboard Events
• Demo: Wiring Up Keyboard Events
• HTML/CSS/JS based Application Framework
• Cross Platform – web application, desktop applications and native
applications
• Speed and Performance – code generation, universal, code splitting
• Productivity – templates, CLI, IDEs
• Full Development Story – testing, animations, accessibility
• Angular is more than a user interface (UI) widget library (such as React)
• Angular is a complete framework for building the UI layer of many kinds
of applications including web applications, desktop applications and
even native applications
• Angular organizes code through modules, provides UI widgets through
components, formats data with pipes, manipulates the DOM through
directives, provides access to REST services through the HTTP module,
enhances HTML forms, application routing, etc…
• The most important aspect of Angular is Component Driven
Development
• Components are the future of web applications, and truly all UI
development across all platforms
• Angular Components are similar to React Components, but they actually
follow the up and coming Web Components standards (which React
does not)
• Understanding Component Driven Development is by far the most
important part of this course
• Angular Components generally follows the Web Components standards
• For more information on Web Components
• http://webcomponents.org
• Custom Elements – used for Components
• HTML Imports – not supported
• Templates – used for Structural Directives
• Shadow DOM – used by Components
• Web Components are placed in web pages using custom elements
• To better understand this concept, think of HTML 5 Audio and Video
elements as components
• Using the <audio> and <video> tags results in a audio and video
component, respectively, being displayed
• Web Components are custom built components which are added to the
page with custom elements
• HTML 5 supports custom element so long as the tag name has a dash in
it; therefore, all components are two word names
• The Web Component's standards use HTML imports to include third-
party components so they can be added to the web page
• While Angular does not support this approach, components are
included via JavaScript files loaded with script elements, SystemJS
dynamic module loading or bundling systems such as Webpack
• The template element is used to specify the template for Web
Components
• The template element is part of the HTML 5 specification
• Angular uses the template element for structural directives
• Typically, developers will not see this directly as it is hidden by the
asterisk syntax
• Web Components use a shadow DOM to isolate the DOM tree of the
component from the DOM tree of the web page itself
• This isolation is referred to as DOM tree and style encapsulation
• This allows CSS styles from the page's DOM tree to not be applied to the
component
• Component's can then define their own styles independent of their
surrounding container
• Angular supports the shadow DOM through native implementations
and polyfills
• Angular works on the following platforms
• Web Browsers
• Electron Framework
• Native iOS and Android Applications with NativeScript
• Server Rendering for Universal Web Applications (isomorphic)
• Angular can be coded with any text editor
• Popular Editors include
• Visual Studio Code
• Atom
• Sublime
• WebStorm
• Visual Studio
• VIM
• Angular applications require some initial project configuration to get up
and running
• There are many ways to get started
• Angular CLI
• Numerous Starter Projects
• From Scratch
• This course will use a starter project configured with WebPack 2
• The WebPack development server will serve the web pages, and
WebPack will bundle the application files
• The initial starter project can be downloaded from GitHub
• Git is not required, simply fire up a web browser, and visit the following
link
• https://github.com/training4developers/mastering-angular-starter
• In the demonstration we will download, configure and fire up the project
Demo
Setting Up the Angular Starter Application
• Angular Modules are not the same thing as ES2015 Modules
• Organize Parts of a Angular Application
• Components must be registered with a Module to be used
• Modules provide a declarations option for configure template items
such as components, pipes, and other directives
• All Angular applications contain an App Module which is used by
Angular to load the application parts and bootstrap the application
• All Angular applications contain a root component commonly named
App Component which is loaded by the App Module
• Classes are part of ES2015
• Fundamentally, they are nothing more than a syntax improvement for
old-school function constructors and prototype inheritance
• Angular uses classes to define many of an application's parts, but then
determines what each part does through a decorator
• Decorators are not part of ES2015 but provided by TypeScript
• They follow the composition pattern of inheritance
• When a component is referenced in the template, Angular creates an
instance of the component class
• The instance of the component class contains data, event handlers and
lifecycle functions
• The component data is bound to the template via template variables (or
more generally known as template expressions)
• For Angular 1 developers, the component instance can be thought of as
the controllerAs object
Demo
Add a Header to the Application
• Commonly, component data is more than a primitive value
• Component data can objects such as arrays
• Working with a collection data in a component's template required a
special structural directive named ngFor.
• The directive ngFor is used to iterate over an array of data, producing
new DOM objects for item in the array
The variable colors is an array of
<ul> string values
<li *ngFor="let color of colors">
{{color}} The variable color will represent each
</li> color as the colors array is iterated
</ul> over.