Lab1 Angular PDF
Lab1 Angular PDF
Lab1 Angular PDF
Lab 1 Components
Lab 1.1: Basics
1. Build the app using the CLI:
Enter the following command, which will create a new Angular app in a
folder called Start and will also create and spew out lots of files:
cd components-ex1
ng serve
3. Open app:
You should see the text “welcome to app!” as shown in Figure below. That
means your project is running.
4. Edit component:
<p>
Reversed: {{getReversed(title)}}
</p>
`,
styles: [] })
Your app should be working at localhost:4200. Note how the template uses
two expressions: one to show the length of the title and another to reverse the
title using a method in the class.
Lab 1.2: One way Data Binding
This component will list some cars and let you click the View button to view
an article about the car, as shown in Figure below
cd components-ex2
ng serve
3.Open app:
Open your web browser and browse to localhost:4200. You should see
the text “welcome to app!” That means your project is running.
4.Edit component:
`,
styles: []
})
showCar(event){
const desc = event.target.parentElement.dataset.desc;
if (window.confirm('If you click "ok" you would be redirected to an
article about the ' + desc + '. Cancel will load this website ')){
window.location.href=event.target.parentElement.
dataset.article;
}
}
5. Create class:
return this._id;
}
cd components-ex3
ng serve
6.Open app:
Open your web browser and browse to localhost:4200. You should see the
text “welcome to app!” That means your project is running.
7.Edit module:
@Component({
selector: 'app-root',
template: `
<p>
Foreground: <input [(ngModel)]="fg" />
</p>
<p>
Background: <input [(ngModel)]="bg" />
</p>
<div [ngStyle]="{'color': fg, 'background-color': bg,
'padding': '5px'}">
Test
</div>
`,
styles: []
})
export class AppComponent {
fg = "#ffffff";
bg = "#000000";
}
1. Build the app using the CLI: Enter the following command:
ng new
components-ex400 --inline-template --inline-style
ng serve
@Component({
selector: 'app-root',
template: `
<input #input type="text" (input)="textInput($event)"
value=""/>
<hr>
Upper-Case: {{upperCase}}
<br/>
Lower-Case: {{lowerCase}}
`,
styles: [] })
ngAfterViewInit() {
this.inputBox.nativeElement.focus()
s}