Note on JavaScript and TypeScript: TypeScript is a strongly typed programming language that builds on JavaScript — TypeScript is a superset of JavaScript that includes static typing. All JavaScript programs are valid TypeScript. TypeScript enforces type checking at compile time. Since web browsers cannot run TypeScript, TypeScript programs are compiled into JavaSript programs before the browsers can run them.
ng new project-or-app-name
@NgModule
decoratorAppModule
) acts similar to the root namespace (or a package) in Java@NgModule
declarator has several properties:
declarations
— specify the components that are defined in this module.
Note: components must be declared in NgModule
before they can be used.
exports
— specify which components should be visible and
usable in the component templates of other NgModules
.imports
— describe which dependencies this module has.
providers
— for dependency injection.
When module A requires module B to run,
B is a dependency of A.
Therefore, B must be imported into A, using
import {B} from 'name-of-module-or-class-B-is-in';
bootstrap
— instruct Angular which component
must be loaded as the top-level component when this module is used to
bootstrap an app
ng generate module module-name
@Component
)ng generate component component-name
import { Component } from '@angular/core'; @Component( { selector: 'name-of-this-component', templateUrl: './view-this-component-will-handle.html', styleUrls: ['./list-of-style-file-to-be-used.css'] }) export class AppComponent { property-name = 'value'; function-name(param1: data-type, param2: data-type): return-type { some-statements-for-this-function-or-controller } }
export class model-name { constructor( public property1: data-type, public property2: data-type, public property3: data-type ) {} }
ng generate class model-or-class-name
ng serve
),
ng
will look at the angular.json file to find the entry point to the Angular app.
At the high level:
AppModule
is used to bootstrap the app.
AppModule
is specified in src/app/app.module.tsAppModule
specifies which component to use as the top-level component,
which is AppComponent
(from in-class examples)AppComponent
has <app-root>
tags
(specified as a selector
in app.component.ts file)