Angular Commands
Angular Commands
Angular Commands
Class
The class decorator. The class is defined in TypeScript. The class
normally has the following syntax in TypeScript.
Syntax
class classname {
Propertyname: PropertyType = Value
}
Parameters
Example
Template
This is the view which needs to be rendered in the application.
Syntax
Template: '
<HTML code>
class properties
'
Parameters
Example
template: '
<div>
<h1>{{appTitle}}</h1>
<div>To Tutorials Point</div>
</div>
'
Metadata
This is used to decorate Angular JS class with additional
information.
Let’s take a look at the completed code with our class, template,
and metadata.
Example
@Component ({
selector: 'my-app',
template: ` <div>
<h1>{{appTitle}}</h1>
<div>To Tutorials Point</div>
</div> `,
})
<body>
<my-app></my-app>
</body>
Output
Now if we go to the browser and see the output, we will see that
the output is rendered as it is in the component.
Template
template: '
<div>
<h1>{{appTitle}}</h1>
<div>To Tutorials Point</div>
</div>
'
This is known as an inline template. There are other ways to define
a template and that can be done via the templateURL command.
The simplest way to use this in the component is as follows.
Syntax
templateURL:
viewname.component.html
Parameters
viewname − This is the name of the app component module.
This defines a simple div tag and references the appTitle property
from the app.component class.
@Component ({
selector: 'my-app',
templateUrl: 'app/app.component.html'
})
From the above code, the only change that can be noted is from
the templateURL, which gives the link to the app.component.html
file which is located in the app folder.
Step 4 − Run the code in the browser, you will get the following
output.
1. Install Node Js
2. Angular, the Angular CLI, and Angular applications depend on npm packages for many features and
functions, Check version npm -v
cd my-app
ng serve --open
The ng serve command launches the server, watches your files, and rebuilds the app as you make
changes to those files.
The --open (or just -o) option automatically opens your browser to http://localhost:4200/.
App- app.component.html
Wishcartproject-
Data Binding-One-way from data source to view target with
Array []
1. Create new project- ng new wishcartproject. The list of cart would be shared across
the application
2. Go to app.component.ts import common module and Add items array in export class
AppComponent
https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
4. Go to app.component.html delete everything and access friend list
<ul>
<li *ngFor="let frnd of friendslist">
{{ frnd.name }} {{ frnd.age }}
</li>
</</ul>
Output
4. Go to app.component.ts import ListItem class, common module and Add items array
in export class AppComponent
Output
<div class="container">
<div *ngIf="items.length==0; then noItems else showItems">
</div>
<ng-template #noItems>
There is no items to display
</ng-template>
<ng-template #showItems>
<ul class="Cart-Items">
<li *ngFor="let item of items">
app.component.ts change class AppComponent
Output
Wishcartproject-
Data Binding-One-way from data source to view target with
Class Attribute & Properties []
app.component.html
<div class="container">
<div *ngIf="items.length==0; then noItems else showItems">
</div>
<ng-template #noItems>
Output
Wishcartproject-
Data Binding-One-way from view target to data source with
Event Binding () (Property Binding)
app.component.html
<div class="container">
<div *ngIf="items.length==0; then noItems else showItems">
app.component.ts change class AppComponent
Wishcartproject-
Data Binding-Two-way sequence of view to source to view
with Event Binding [()]
app.component.html
<div class="container">
@Component({
selector: 'app-root',
Output