Edit Application

Overview

These are all the folders and files the Angular CLI created for you. This is your entire Angular project.
Angular Project Overview

Project dependencies

One of the most important files is Package.json which is your dependency configuration file.
Here you can see all the dependencies of your project like Angular 6 and these are third-party packages your project needs to run correctly.
All devDependencies are only required for development.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{
"name": "my-app",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.1.0",
"@angular/common": "^6.1.0",
"@angular/compiler": "^6.1.0",
"@angular/core": "^6.1.0",
"@angular/forms": "^6.1.0",
"@angular/http": "^6.1.0",
"@angular/platform-browser": "^6.1.0",
"@angular/platform-browser-dynamic": "^6.1.0",
"@angular/router": "^6.1.0",
"core-js": "^2.5.4",
"rxjs": "^6.0.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.7.0",
"@angular/cli": "~6.1.5",
"@angular/compiler-cli": "^6.1.0",
"@angular/language-service": "^6.1.0",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1",
"typescript": "~2.7.2"
}
}

Index page

The Index page described in app.component.html of $Root/src/app.(Actually, Index page defined in index.html of $Root directory, and app.component.html inject by app.component.ts with app-root tag which will talk in the future)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!--The content below is only a placeholder and can be replaced.-->
<div style="text-align:center">
<h1>
Welcome to {{ title }}!
</h1>
<img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
</div>
<h2>Here are some links to help you start: </h2>
<ul>
<li>
<h2><a target="_blank" rel="noopener" href="https://angular.io/tutorial">Tour of Heroes</a></h2>
</li>
<li>
<h2><a target="_blank" rel="noopener" href="https://github.com/angular/angular-cli/wiki">CLI Documentation</a></h2>
</li>
<li>
<h2><a target="_blank" rel="noopener" href="https://blog.angular.io/">Angular blog</a></h2>
</li>
</ul>

And the Index page shows as below:
Angular Index

Modify this block:

1
2
3
<h1>
Welcome to {{ title }}!
</h1>

to

1
2
3
<h1>
This is my first App!
</h1>

Then Index page content changed to:
Angular Index Modified

You may see a special code in previous block as Edit Application, this is dynamic combination with the value in TypeScript files. Angular allows us to mix static HTML code and dynamic things we want to output in that code.

The title defined in app.component.ts file as:

1
2
3
4
5
6
7
8
9
10
11
import { Component } from '@angular/core';


@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'my-app';
}

Now, let us change the title value from my-app to First Application and insert another variable user as below:

1
2
3
4
export class AppComponent {
title = 'First Application';
user = 'Vince'
}

And update the html block as

1
2
3
<h1>
{{ user }}'s {{ title }}!
</h1>

The index page presents like:
Angular Index with user

Data binding

We use curly braces for data binding - like Edit Application; this process is called interpolation. We have already seen in our previous examples how we declared the value to the variable title and the same is printed in the browser.
The variable in the app.component.html file is referred as Edit Application and the value of title is initialized in the app.component.ts file and in app.component.html, the value is displayed.

With data binding feature, we could build more fancy webs by update the app.module.ts as:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';

import { AppComponent } from './app.component';

@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }

Update app.component.html as:

1
2
3
4
5
6
7
8
9
<div style="text-align:center">
<h1>
{{ user }}'s {{ title }}!
</h1>
<p> User </p> <br>
<input type = "text" [(ngModel)] = "user">
<p> Title </p> <br>
<input type = "text" [(ngModel)] = "title">
</div>

Then the index page changed to:
Angular Data Binding

The content will sync with input simultaneously.

Author: Zhengyang Wu
Link: https://vincewu.net/2018/08/23/Angular/Angular-4-Edit-Application/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.