By now, we're already familiar with the core of the framework. We know how to define components and directives in order to develop the view of our applications. We also know how to encapsulate business-related logic into services and wire everything together with the DI mechanism of Angular.
In this chapter, we'll explain a few more concepts that will help us build real-life Angular applications. They are as follows:
Let's begin!
Throughout the process of explaining the listed concepts, we'll develop a sample application that contains a repository of developers. Before we start coding, let's discuss the structure of the application.
The "Coders repository" will allow its users to add developers, either by filling a form with details about them, or by providing the GitHub handle for the developer and importing their profile from GitHub.
The application will have the following views:
The end result of the application's home page will look as follows:
Figure 1
In this chapter, we will build only a few of the listed views. The rest of the application will be explained in Chapter 7, Explaining Pipes and Communicating with RESTful Services.
Each developer will be an instance of the following class:
// ch6/ts/multi-page-template-driven/developer.ts export class Developer { public id: number; public githubHandle: string; public avatarUrl: string; public realName: string; public email: string; public technology: string; public popular: boolean; }
All the developers will reside within the DeveloperCollection
class:
// ch6/ts/multi-page-template-driven/developer_collection.ts class DeveloperCollection { private developers: Developer[] = []; getUserByGitHubHandle(username: string) { return this.developers .filter(u => u.githubHandle === username) .pop(); } getUserById(id: number) { return this.developers .filter(u => u.id === id) .pop(); } addDeveloper(dev: Developer) { this.developers.push(dev); } getAll() { return this.developers; } }
The classes mentioned here encapsulate a simple business logic and don't have anything Angular-specific, so we won't get into any details.
Now, let's continue with the implementation by exploring the new router.