In this book, we will have a couple of components and services that will work together to achieve a goal. But we need a root component to act as a communication center between all these players. This root component will control the application flow. Let's start by creating this component:
app.ts
file, and notice the export line:export class AppComponent {}
export
keyword simply indicates that we are willing to share this class with every other player in the project. In other words, if anyone needs this class, they just need to import it in their own body.AppComponent
class as the root component for our project, that is why we have the Component function imported from the Angular2 core module:import {Component} from 'angular2/core'; export class Sherlock {}
app.ts
file as a component. A decorator contains some meta-data that defines the nature of a class and how it is going to do it.// src/app/app.ts import {Component} from 'angular2/core'; @Component({ selector: 'app', templateUrl: './app.html' })
@Component
decorator is a selector. Basically, it is a CSS selector, which means whatever is assigned to this property will become a valid HTML tag later. In other words, it is perfectly fine to have a custom tag like <app></app>
in your HTML template. The templateUrl
property contains the path and the file for this Component's template.app.html
file:
# src/app/app.html <h3> Angular 2 Seed </h3> <nav> <a [routerLink]="['/']">Home</a> <a [routerLink]="['/about']">About</a> <a [routerLink]="['/github','angular']">Github Repos</a> </nav> <main> <router-outlet></router-outlet> </main>
<h1>The Sherlock Project</h1>
3.143.3.208