var let = 3;
for (let i_1 = 0; i_1 < 10; i_1++) {
}
gives
var i = 3;
for (var i_1 = 0; i_1 < 10; i_1++) {
}
== primitives ==
let greet: string = "Greetings";
let geeks: string = "Geeks For Geeks";
console.log(greet + " from " + geeks);
// save the file as hello.ts
Install and transpile
npm install -g typescript
tsc hello.ts
run
node hello.js
run without binding to the host name
ng serve --port 8003 --host 0.0.0.0
run with polling
ng serve --poll 500
Watch changes in code and auto rebuild
ng build --watch --poll 500 --configuration development
To check if any module in a project is 'old': ''npm outdated''.
To update all dependencies, if you are confident this is desirable: ''npm update''.
To update all dependencies, if you are confident this is desirable: ''npm update xml2js''.
To update package.json version numbers, append the --save flag: ''npm update --save''.
ng build --watch --poll 500 --configuration development
add a dependency package to your project. E.g. `@angular/material`
ng add @angular/material
== functions==
declare type ClassDecorator = (Target:TFunction) => TFunction | void;
For Classes
alf-component1 and {{name}} works!
{{name}} hero works!
// this just HIDES the element but keeps it in DOM{{name}} hero works!
{{name}} hero works!
Hero was not found
...
The component stub can be generated.
Also under a "NGModule", in a subfolder. Here component ''heroList'' under module and subfolder ''heroes''.
ng generate component heroes/heroList --module=heroes
== Decorator ==
Java like annotations. Metadata added to the class.
@Component({
selector: 'app-hello-world',
templateUrl: './hello-world.component.html',
styleUrls: ['./hello-world.component.css']
})
== Templates ==
The HTML content of a component is called the template and is defined in the
templateUrl property. It denotes the path of the HTML file of the component relative
to the component class file:
See the reference to the template in the decorator above.
templateUrl: './app.component.html'
== Template tags, mustache tags ==
Variables, defined in Components
can be referenced in templates:
The ''%% {{ }} %%'' syntax is one example of the Angular template language, called interpolation.
It reads the **name property** of the component class,
converts its value to text,
and renders it on the screen.
constructor() {
this.name = 'Felipe'; // set the name
}
Hello {{ name }}
constructor() {
this.names = ['Ari', 'Carlos', 'Felipe', 'Nate'];
}
- Hello {{ name }}
== Property binding ==
The property inside square brackets is
called the **target property** and is the property.
The variable on the right is called the **template expression** and corresponds to the
public title property of the component.
@NgModule({
declarations: [
AppComponent,
VideoItemComponent
],
imports: [
BrowserModule, HttpModule, RouterModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
* declarations: The components, directives, and pipes that are registered with the module.
* imports: Other modules that contain declarations to be used by this module. The Angular CLI defines CommonModule automatically for us in this property. It is a module that is always used in Angular applications because it contains all the built-in directives and pipes that we usually would like to use. Be careful not to get caught in circular references when you import a module that already imports yours.
* exports: Angular artifacts that are defined in declarations and are available for other modules to use. This is the public API of the module. It defines what is publicly accessible or not. Everything else that's not explicitly exported would be considered private or internal to the module.
* providers: Services that are provided from the module and are accessible from any module of the application. We'll learn more about providers in the How dependency injection works in Angular section.
* bootstrap: The main component of the application that will be rendered when the application starts up. This property is set only once in the main application module, AppModule, and is usually AppComponent. Typically, you should not change it unless there is a particular reason to do so.
== Providers ==
providers is used for dependency injection. So to make a service available to be injected throughout
our application, we will add it here.
== Interactions ==
when the button is clicked, it will call a function called addArticle(), which we need to define
on the AppComponent class
The **#newlink** and **#newtitle** are used, to mark input variables for the addArticle() function.
==== Typings ====
JavaScript is untyped, meaning that we can pass around and use data, objects and functions with no constraints. We can write code that calls methods that don't exist on an object, or reference variables that we don't have. These kinds of mistakes can be hard to discover when you are writing code, and it can lead to unstable and buggy code. Doing big changes of your code can become difficult and risky as you don't immediately see if some changes conflicts with the rest of the code somewhere else.
TypeScript is mainly about adding types to JavaScript. That means that TypeScript requires you to accurately describe the format of your objects and your data. When you do that, that means that the compiler can investigate your code and discover errors. It can see that you are trying to call a function with the wrong kinds of arguments, or reference a variable that is not accessible in the current scope.
When you write TypeScript yourself, this formal description of the code is part of the code itself.
However, when you use external libraries like jQuery or moment.js, there are no information of the types in that code. So in order to use it with TypeScript, you also have to get files that describe the types of that code. These are the type declaration files, most often with the file extension name .d.ts. Fortunately people have written those kinds of type declaration files for most common javascript libraries out there.
Typings was just a tool to install those files. It is now best practice to just use npm.
When you have installed those files, which basically only means downloading them and placing them in your project, the TypeScript compiler will understand* that external code and you will be able to use those libraries. Otherwise you would only get errors everywhere.
https://stackoverflow.com/questions/41573822/what-are-typings-in-typescript
# Install Jquery typing
npm install --save @types/jquery
==== Bootstrapping in main.ts ====
How does Angular know, where to start?
What is responsible for booting up the
process of rendering a page on the screen? This **method is called bootstrapping**, and it is
**defined in the main.ts file** inside the src folder.
import { AppModule } from './app/app.module';
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));
==== Intelij IDEA ====
Plugin supports syntax highlighting
https://www.sgalinski.de/typo3-produkte-webentwicklung/typoscript-phpstorm-webstorm-intellij/?utm_source=phpstorm&utm_medium=banner&utm_term=typoscript%20plugin&utm_campaign=phpstorm-typoscript
To have a support for the Idea, you should:
* node installed on **the same machine as Idea**, with aws-cli installed globally (npm install -g angular-cli)
* create the Angular project via Idea (**File > New > Project > Static Web > Angular CLI**) to avoid all kind of errors with work dir and not finding the "ng" executable
* add some arguments to the start script in package.json ("start": "ng serve --port 5230 --host 0.0.0.0 --liveReload true --open true")
* Run via Run > Run "Angular CLI Server"
Then the Browser should automagically pick up all changes, made in Idea
==== Packaging ====
Angular code pieces - can be packaged as a libs.
Both libraries and applications are modules a the end of the day. Their main difference is how they are built and deployed. A library can be packaged and published for easier reuse across projects. An application includes browser specific files for deploying and running in the browser.
In this article we will explore what happens when we build our library, package our library using npm pack. We'll also see how to actually use our library in a separate application.
https://indepth.dev/the-angular-library-series-building-and-packaging/
===== IDE Intellij =====
Plugin supports syntax highlighting https://www.sgalinski.de/typo3-produkte-webentwicklung/typoscript-phpstorm-webstorm-intellij/?utm_source=phpstorm&utm_medium=banner&utm_term=typoscript%20plugin&utm_campaign=phpstorm-typoscript
To have a support for the Idea, you should:
have node installed on the same machine as Idea, with aws-cli installed globally
npm install -g angular-cli)
create the Angular project via Idea ''(File > New > Project > Static Web > Angular CLI)'' to avoid all kind of errors with work dir and not finding the “ng” executable
add some arguments to the start script in package.json
("startdev": "ng serve –port 5230 –host 0.0.0.0 –liveReload true –open true")
You can then add a Profile / Edit Configuration
Profile > npm
Command : run
Script : startdev
Arguments: -- --host 0.0.0.0 --liveReload true --open true
Run via ''Run > Run “startdev”''
Then the Browser should automagically pick up all changes, made in Idea
===== Unit tests =====
Unit-tests in Angular are using Jasmine.
== Config file ==
|test.ts|
"test": "../../test/angular/test.ts",
"include": [
"../../../**/*.spec.ts",
"**/*.spec.ts",
...
ng test
which opens a browser window with html results and a console.
The coolest thing is, that they stay open and recompile every time, when something changes.
{{https://lh3.googleusercontent.com/-RFG9OxFonp0/WqqU9oItbmI/AAAAAAAAAFg/XN409W_V9a8UaRRADvc2WxQRf7_v-odtwCHMYCw/s0/2018-03-15_16-44-53.png}}
===== End to End tests =====
Protractor is an official library to used for writing E2E test suites with an Angular app. \\ It’s nothing but a **wrapper over the Selenium** WebDriverJS Api that translates its succinct code and methods to WebDriver JS methods. That said, you can use WebDriverJS methods too inside your e2e script.
Details: [[devops:tests:protractor]]
===== Typescript =====
Typescript intro in 5 minutes https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html
Primitive types: https://www.typescriptlang.org/docs/handbook/basic-types.html
|boolean|
|number|
|string|
|null|
|array|
|tupel|
|Enum|
|any|
|void|
|never|
|object|
===== Component Lifecycle =====
{{https://lh3.googleusercontent.com/-9Zy7EnBIf4c/W2cdypAx2iI/AAAAAAAAAL0/C33pJzGXOqwnq0KRIIbIqKp0hN2GCUJ5gCHMYCw/s0/2018-08-05_17-54-49.png}}
More: https://codecraft.tv/courses/angular/components/lifecycle-hooks/
===== Async patterns =====
== Promises ==
* They cannot be canceled.
* They are immediately executed.
* They are one-time operations only; there is no easy way to retry them.
* They respond with only one value.