Book Image

TypeScript Blueprints

By : Ivo Gabe de Wolff
Book Image

TypeScript Blueprints

By: Ivo Gabe de Wolff

Overview of this book

TypeScript is the future of JavaScript. Having been designed for the development of large applications, it is now being widely incorporated in cutting-edge projects such as Angular 2. Adopting TypeScript results in more robust software - software that is more scalable and performant. It's scale and performance that lies at the heart of every project that features in this book. The lessons learned throughout this book will arm you with everything you need to build some truly amazing projects. You'll build a complete single page app with Angular 2, create a neat mobile app using NativeScript, and even build a Pac Man game with TypeScript. As if fun wasn't enough, you'll also find out how to migrate your legacy codebase from JavaScript to TypeScript. This book isn't just for developers who want to learn - it's for developers who want to develop. So dive in and get started on these TypeScript projects.
Table of Contents (16 chapters)
TypeScript Blueprints
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface

Creating the first component


Angular is based on components. Components are built with other components and normal HTML tags. Our application will have three components: the forecast page, the about page, and the whole widget. The widget itself, which is referenced in the HTML page, will use the other two widgets.

The widget will show the About page in the third tab, as you can see in the following screenshot:

The forecast component is shown in the first tab of the following screenshot. We will create the forecast and the widget later in this chapter.

The template

A component is a class decorated with some metadata. Decorators are functions that can modify a class or decorate it with some metadata. A simple component that does not have any interaction will look like this:

import { Component } from "angular2/core"; 
 
@Component({ 
  selector: "about-page", 
template: ` 
    <h2>About</h2> 
    This widget shows the weather forecast of Utrecht. 
...