Skip to main content

Angular Tutorial - Angular Components - Angular 7-Angular 8 -Angular 6- Angular Js

Learn Angular from scratch step by step

Angular 7 Components - Angular 8


The most basic building block of your Angular 7 application (and this is a concept that's not new) is the component. A component consists of three primary elements:
  • The HTML template
  • The logic
  • The styling (CSS, Sass, Stylus, etc..)
When we use the Angular CLI to start a new project, it generates a single component, which is found in /src/app/:
/app.component.html
/app.component.scss
/app.component.ts
While we have three files here that represent the three elements above, the .ts (TypeScript) is the heart of the component. Let's take a look at that file:
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title = 'ng7-pre';
}
Here, because this is a component, we're importing Component from the @angular/core library, and then it defines what's called a @Component decorator, which provides configuration options for that particular component.
As you can see, it's referencing the location of the HTML template file and the CSS file with the templateUrl property and the styleUrls property.
The logic of the component resides in the class at the bottom. As you can see, the CLI starter template simply defines a single property called title.
Let's use the Angular CLI to create our own components that we'll need going forward. In the console, issue the following commands:
> ng generate component nav
// output

> ng g c about
// output

> ng g c contact
// output

> ng g c home
// output
Notice we first use the full syntax to generate a component, and then we use a shorthand syntax, which makes life a little bit easier. The commands do the same thing: generate components.
When we generate components this way, it will create a new folder in the /src/ folder based on the name we gave it, along with the respective template, CSS, .ts and .spec (for testing) files.

Comments

Popular posts from this blog

Asp.net grid CRUD with ADO.NET

Asp.net grid CRUD with ADO.NET A GridView is a graphical control element that presents a tabular view of data. A typical Grid View also supports some or all of the following: Clicking a column header to change the sort order of the Grid. Dragging column headers to change their size and their order. The GridView control displays the values of a data source in a table. Each column represents a field, while each row represents a record. Support to data source controls, such as SqlDataSource. Support sort capabilities. Support update and delete capabilities. Support paging capabilities. Support row selection capabilities. Code behind feature access to the GridView object model to dynamically set properties, handle events, and so on. Many key fields. Many data fields for the hyperlink columns. Customized style layout through themes and styles using css and javascript. The following operations can be performed using GridView control in ASP.NET using C# code behind. Fea...

.NET Interview Preparation for Experienced Candidate

.NET Real Time Interview Questionnaire  for Experienced Candidate Architecture Level Questions 1.        SOLID Principles 2.        Dependency Injection 3.        Design Patterns 4.        SingleTon Patterns 5.        Factory Patterns 6.        Repository Patterns 7.        Bidge Patterns 8.        Strategy Patterns 9.        Software Methodology ( Agile) 10.    Realtime Project 11.    Security ( Authentication & Authorisation) 12.    Lazy Loading 13.    Caching 14.    Performance Tuning 15.    Loosely coupling 16.    Logger 17.    IIS Deployment   C# Basic & Advanced 18.    Garbage collec...

Angular NgModules - angular modules simple example - Angular 7-6-5-4-3-2-1-AngularJs

Angular Module In Angular, Modules are the collection of the Components, Service directives, and Pipes which are related such that they can be combined to form a module.   A module is a collection of services, directives, controllers, filters, and configuration information.  angular . module  is used to configure the  What's an NgModule NgModules are simply TypeScript classes decorated with the  @NgModule  decorator imported from the  @angular/core  package. Modules provide a way for developers to organize their code and they are particularly helpful for managing large apps. In Angular, Modules are the collection of the Components, Service directives, and Pipes which are related such that they can be combined to form a module.