2019-12-02 12:47:19 -08:00
# Setup for upgrading from AngularJS
2017-03-27 16:08:53 +01:00
2019-08-19 10:23:42 -07:00
<!--
2019-04-02 00:12:55 -06:00
Question: Can we remove this file and instead direct readers to https://github.com/angular/quickstart/blob/master/README.md
-->
2017-04-01 01:57:13 +02:00
2019-04-02 00:12:55 -06:00
<div class="alert is-critical">
2017-02-22 18:09:39 +00:00
2019-08-19 10:23:42 -07:00
**Audience: ** Use this guide **only ** in the context of [Upgrading from AngularJS ](guide/upgrade "Upgrading from AngularJS to Angular" ) or [Upgrading for Performance ](guide/upgrade-performance "Upgrading for Performance" ).
Those Upgrade guides refer to this Setup guide for information about using the [deprecated QuickStart GitHub repository ](https://github.com/angular/quickstart "Deprecated Angular QuickStart GitHub repository" ), which was created prior to the current Angular [CLI ](cli "CLI Overview" ).
2017-04-01 01:57:13 +02:00
2019-08-19 10:23:42 -07:00
**For all other scenarios, ** see the current instructions in [Setting up the Local Environment and Workspace ](guide/setup-local "Setting up for Local Development" ).
2017-04-01 01:57:13 +02:00
2017-05-04 18:46:43 +02:00
2019-04-02 00:12:55 -06:00
</div>
<!--
The <live-example name=quickstart>QuickStart live-coding</live-example> example is an Angular _ playground _ .
There are also some differences from a local app, to simplify that live-coding experience.
In particular, the QuickStart live-coding example shows just the AppComponent file; it creates the equivalent of app.module.ts and main.ts internally for the playground only.
-->
2017-04-01 01:57:13 +02:00
2019-04-02 00:12:55 -06:00
This guide describes how to develop locally on your own machine.
Setting up a new project on your machine is quick and easy with the [QuickStart seed on github ](https://github.com/angular/quickstart "Install the github QuickStart repo" ).
2017-04-01 01:57:13 +02:00
2019-04-02 00:12:55 -06:00
**Prerequisite: ** Make sure you have [Node.js® and npm installed ](guide/setup-local#prerequisites "Angular prerequisites" ).
{@a clone}
2017-05-26 21:28:06 +02:00
## Clone
2017-02-22 18:09:39 +00:00
Perform the _ clone-to-launch _ steps with these terminal commands.
2021-05-07 11:28:39 +01:00
<code-example language="sh">
2017-04-01 01:57:13 +02:00
git clone https://github.com/angular/quickstart.git quickstart
cd quickstart
npm install
2017-02-22 18:09:39 +00:00
</code-example>
{@a download}
2017-04-01 01:57:13 +02:00
2017-05-26 21:28:06 +02:00
## Download
2017-03-31 12:23:16 +01:00
<a href="https://github.com/angular/quickstart/archive/master.zip" title="Download the QuickStart seed repository">Download the QuickStart seed</a>
2017-02-22 18:09:39 +00:00
and unzip it into your project folder. Then perform the remaining steps with these terminal commands.
2021-05-07 11:28:39 +01:00
<code-example language="sh">
2017-04-01 01:57:13 +02:00
cd quickstart
npm install
2017-02-22 18:09:39 +00:00
</code-example>
{@a non-essential}
## Delete _non-essential_ files (optional)
You can quickly delete the _ non-essential _ files that concern testing and QuickStart repository maintenance
(***including all git-related artifacts*** such as the `.git` folder and `.gitignore` !).
2017-04-10 16:51:13 +01:00
<div class="alert is-important">
2017-02-22 18:09:39 +00:00
2017-04-01 01:57:13 +02:00
2017-02-22 18:09:39 +00:00
Do this only in the beginning to avoid accidentally deleting your own tests and git setup!
2017-04-10 16:51:13 +01:00
</div>
2017-02-22 18:09:39 +00:00
2017-04-01 01:57:13 +02:00
2017-02-22 18:09:39 +00:00
Open a terminal window in the project folder and enter the following commands for your environment:
### OS/X (bash)
2017-03-30 20:04:18 +01:00
2021-05-07 11:28:39 +01:00
<code-example language="sh">
2017-04-01 01:57:13 +02:00
xargs rm -rf < non-essential-files.osx.txt
rm src/app/*.spec*.ts
rm non-essential-files.osx.txt
2017-02-22 18:09:39 +00:00
</code-example>
2017-04-01 01:57:13 +02:00
2017-02-22 18:09:39 +00:00
### Windows
2017-03-30 20:04:18 +01:00
2021-05-07 11:28:39 +01:00
<code-example language="sh">
2017-04-01 01:57:13 +02:00
for /f %i in (non-essential-files.txt) do del %i /F /S /Q
rd .git /s /q
rd e2e /s /q
2017-02-22 18:09:39 +00:00
</code-example>
2021-11-05 19:49:51 +02:00
## Update dependency versions
Since the quickstart repository is deprecated, it is no longer updated and you need some additional steps to use the latest Angular.
1. Remove the obsolete `@angular/http` package (both from `package.json > dependencies` and `src/systemjs.config.js > SystemJS.config() > map` ).
2. Install the latest versions of the Angular framework packages by running:
```sh
npm install --save @angular/common@latest @angular/compiler@latest @angular/core@latest @angular/forms@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/router@latest
` ``
3. Install the latest versions of other packages used by Angular (RxJS, TypeScript, Zone.js) by running:
` ``sh
npm install --save rxjs@latest zone.js@latest
npm install --save-dev typescript@latest
` ``
4. Install the ` systemjs-plugin-babel` package. This will later be used to load the Angular framework files, which are in ES2015 format, using SystemJS.
` ``sh
npm install --save systemjs-plugin-babel@latest
` ``
5. In order to be able to load the latest Angular framework packages (in ES2015 format) correctly, replace the relevant entries in ` src/systemjs.config.js`:
<code-examples
path="upgrade-phonecat-2-hybrid/systemjs.config.1.js"
region="angular-paths">
</code-example>
6. In order to be able to load the latest RxJS package correctly, replace the relevant entries in ` src/systemjs.config.js`:
<code-examples
path="upgrade-phonecat-2-hybrid/systemjs.config.1.js"
region="rxjs-paths">
</code-example>
7. In order to be able to load the ` tslib` package (which is required for files transpiled by TypeScript), add the following entry to ` src/systemjs.config.js`:
<code-examples
path="upgrade-phonecat-2-hybrid/systemjs.config.1.js"
region="tslib-paths">
</code-example>
8. In order for SystemJS to be able to load the ES2015 Angular files correctly, add the following entries to ` src/systemjs.config.js`:
<code-examples
path="upgrade-phonecat-2-hybrid/systemjs.config.1.js"
region="plugin-babel">
</code-example>
9. Finally, in order to prevent TypeScript typecheck errors for dependencies, add the following entry to ` src/tsconfig.json`:
` ``json
{
"compilerOptions": {
"skipLibCheck": true,
// ...
}
}
` ``
With that, you can now run ` npm start` and have the application built and served.
Once built, the application will be automatically opened in a new browser tab and it will be automatically reloaded when you make changes to the source code.
2017-02-22 18:09:39 +00:00
{@a seed}
2017-04-01 01:57:13 +02:00
2017-02-22 18:09:39 +00:00
## What's in the QuickStart seed?
2017-03-27 16:08:53 +01:00
2017-04-01 01:57:13 +02:00
2019-04-02 00:12:55 -06:00
The **QuickStart seed** provides a basic QuickStart playground application and other files necessary for local development.
Consequently, there are many files in the project folder on your machine,
2018-10-10 14:28:49 -07:00
most of which you can [learn about later](guide/file-structure).
2017-03-27 16:08:53 +01:00
2019-08-19 10:23:42 -07:00
<div class="alert is-helpful">
**Reminder:** The "QuickStart seed" example was created prior to the Angular CLI, so there are some differences between what is described here and an Angular CLI application.
</div>
2017-03-27 16:08:53 +01:00
{@a app-files}
2017-04-01 01:57:13 +02:00
2017-03-27 16:08:53 +01:00
Focus on the following three TypeScript (` .ts`) files in the **` /src`** folder.
2017-03-30 20:04:18 +01:00
2017-04-11 21:44:52 +01:00
<div class='filetree'>
2017-03-27 16:08:53 +01:00
2017-04-11 21:44:52 +01:00
<div class='file'>
2017-03-27 16:08:53 +01:00
src
2017-04-11 21:44:52 +01:00
</div>
<div class='children'>
<div class='file'>
2017-03-27 16:08:53 +01:00
app
2017-04-11 21:44:52 +01:00
</div>
<div class='children'>
<div class='file'>
2017-03-27 16:08:53 +01:00
app.component.ts
2017-04-11 21:44:52 +01:00
</div>
2017-03-27 16:08:53 +01:00
2017-04-11 21:44:52 +01:00
<div class='file'>
2017-03-27 16:08:53 +01:00
app.module.ts
2017-04-11 21:44:52 +01:00
</div>
2017-03-27 16:08:53 +01:00
2017-04-11 21:44:52 +01:00
</div>
2017-03-27 16:08:53 +01:00
2017-04-11 21:44:52 +01:00
<div class='file'>
2017-03-27 16:08:53 +01:00
main.ts
2017-04-11 21:44:52 +01:00
</div>
2017-03-27 16:08:53 +01:00
2017-04-11 21:44:52 +01:00
</div>
2017-03-27 16:08:53 +01:00
2017-04-11 21:44:52 +01:00
</div>
2017-03-27 16:08:53 +01:00
<code-tabs>
2018-10-11 13:29:59 +02:00
<code-pane header="src/app/app.component.ts" path="setup/src/app/app.component.ts">
2017-03-27 16:08:53 +01:00
</code-pane>
2018-10-11 13:29:59 +02:00
<code-pane header="src/app/app.module.ts" path="setup/src/app/app.module.ts">
2017-03-27 16:08:53 +01:00
</code-pane>
2018-10-11 13:29:59 +02:00
<code-pane header="src/main.ts" path="setup/src/main.ts">
2017-03-27 16:08:53 +01:00
</code-pane>
</code-tabs>
2017-04-01 01:57:13 +02:00
2017-06-09 17:48:53 -04:00
All guides and cookbooks have _at least these core files_.
2017-02-22 18:09:39 +00:00
Each file has a distinct purpose and evolves independently as the application grows.
2021-05-10 19:48:18 +00:00
Files outside ` src/` concern building, deploying, and testing your application.
2017-02-22 18:09:39 +00:00
They include configuration files and external dependencies.
2021-05-10 19:48:18 +00:00
Files inside ` src/` "belong" to your application.
2017-02-22 18:09:39 +00:00
Add new Typescript, HTML and CSS files inside the ` src/` directory, most of them inside ` src/app`,
unless told to do otherwise.
The following are all in ` src/`
2017-03-30 20:04:18 +01:00
2017-02-22 18:09:39 +00:00
<style>
td, th {vertical-align: top}
</style>
2017-03-30 20:04:18 +01:00
2017-02-22 18:09:39 +00:00
<table width="100%">
<col width="20%">
</col>
<col width="80%">
</col>
<tr>
<th>
File
</th>
<th>
Purpose
</th>
</tr>
<tr>
<td>
2017-03-31 12:23:16 +01:00
<code>app/app.component.ts</code>
2017-02-22 18:09:39 +00:00
</td>
<td>
2017-04-01 01:57:13 +02:00
Defines the same ` AppComponent` as the one in the QuickStart playground.
It is the **root** component of what will become a tree of nested components
2017-06-09 17:48:53 -04:00
as the application evolves.
2017-02-22 18:09:39 +00:00
</td>
</tr>
2017-03-31 12:23:16 +01:00
<tr>
2017-03-30 20:04:18 +01:00
2017-02-22 18:09:39 +00:00
<td>
<code>app/app.module.ts</code>
</td>
<td>
2017-04-01 01:57:13 +02:00
2017-06-09 17:48:53 -04:00
Defines ` AppModule`, the [root module](guide/bootstrapping "AppModule: the root module") that tells Angular how to assemble the application.
2019-08-19 10:23:42 -07:00
When initially created, it declares only the ` AppComponent`.
Over time, you add more components to declare.
2017-02-22 18:09:39 +00:00
</td>
</tr>
<tr>
<td>
2017-03-31 12:23:16 +01:00
<code>main.ts</code>
2017-02-22 18:09:39 +00:00
</td>
<td>
2017-04-01 01:57:13 +02:00
2017-04-30 22:10:32 +02:00
Compiles the application with the [JIT compiler](guide/glossary#jit) and
2017-07-04 10:58:20 -04:00
[bootstraps](guide/bootstrapping)
2017-04-01 01:57:13 +02:00
the application's main module (` AppModule`) to run in the browser.
The JIT compiler is a reasonable choice during the development of most projects and
2019-08-19 10:23:42 -07:00
it's the only viable choice for a sample running in a _live-coding_ environment such as Stackblitz.
Alternative [compilation](guide/aot-compiler), [build](guide/build), and [deployment](guide/deployment) options are available.
2017-04-01 01:57:13 +02:00
2017-02-22 18:09:39 +00:00
</td>
</tr>
</table>
2020-08-01 04:43:18 +09:00
## Appendix: Test using ` fakeAsync()/waitForAsync()`
2018-04-01 23:09:00 +09:00
2021-05-04 21:16:13 +05:30
If you use the ` fakeAsync()/waitForAsync()` helper functions to run unit tests (for details, read the [Testing guide](guide/testing-components-scenarios#fake-async)), you need to import ` zone.js/testing` in your test setup file.
2018-04-01 23:09:00 +09:00
<div class="alert is-important">
If you create project with ` Angular/CLI`, it is already imported in ` src/test.ts`.
</div>
And in the earlier versions of ` Angular`, the following files were imported or added in your html file:
` ``
2021-02-15 10:08:30 +01:00
import 'zone.js/plugins/long-stack-trace-zone';
import 'zone.js/plugins/proxy';
import 'zone.js/plugins/sync-test';
import 'zone.js/plugins/jasmine-patch';
import 'zone.js/plugins/async-test';
import 'zone.js/plugins/fake-async-test';
2018-04-01 23:09:00 +09:00
` ``
2019-04-02 00:12:55 -06:00
You can still load those files separately, but the order is important, you must import ` proxy` before ` sync-test`, ` async-test`, ` fake-async-test` and ` jasmine-patch`. And you also need to import ` sync-test` before ` jasmine-patch`, so it is recommended to just import ` zone-testing` instead of loading those separated files.