concept angular component in category nativescript

This is an excerpt from Manning's book NativeScript in Action.
Angular components are a collection of UI elements and code that are walled-off from other components. By walled-off, we mean that components can’t directly reach into each other. In a way, they have a force-field around them, limiting the data and interactions that come into the component and go out of the component.
As you’ll recall, you learned that the app.module.ts file is the entry point for NativeScript-with-Angular apps. You also learned that Angular components are like NativeScript pages, but let’s dive a little deeper into how components and pages are similar. Figure 16.1 shows the contents of an Angular component.
Figure 16.1 Angular components have markup, style, and code.
![]()
Angular components comprise of three pieces: markup, styling, and code. The Angular-specific pieces of a component are just like the vanilla NativeScript pieces of a page, but with implementation differences. Angular components are built with HTML markup, CSS styling, and TypeScript code, and vanilla NativeScript pages are built with XML markup, CSS styling, and JavaScript code.
Figure 16.2 shows the implementation differences between Angular components and NativeScript pages.
Figure 16.2 The differences between a NativeScript Page and Angular Component.
![]()
Writing the code for apps in different language variants isn’t the only code difference: the structure and content of the code is different. The difference may be obvious to some, but we want to point it out to ensure we’re on the same page. The code within Angular components is Angular-specific, using Angular constructs like the @Component declaration we saw in chapter 15 and in listing 16.1.
Listing 16.1 The app.component.ts file showing Angular constructs like the @Component declaration
import { Component } from "@angular/core"; @Component({ selector: "my-app", template: ` <ActionBar title="Hello Angular!"></ActionBar> <!-- Your UI components go here --> ` }) export class AppComponent { // Your TypeScript logic goes here }There is a final difference between Angular components and NativeScript pages in how the view markup is written (HTML versus XML), and you’ll learn about it shortly. But it’s easier to teach you about the difference if we’ve built an Angular component first. So, let’s tackle our first component (or page) of the Pet Scrapbook Angular: the Home component.