How to develop AngularJS 2 applications using the VS Code editor
This article mainly introduces you to the relevant information on how to use VS Code to develop your first AngularJS 2 application. The article introduces it in detail through sample code, which will be a certain reference for everyone's study or work. Value, friends in need can come and take a look below.
Preface
I have previously introduced you to the Angular2 development environment setup tutorial VS Code. This article will introduce in detail how to develop AngularJS2 using VS Code. The relevant content of the application is shared for everyone's reference and study. I won't say much below, let's take a look at the detailed introduction.
Running environment:
1, Windows 10
2, Node 6.7.0
3, npm 3.10.8
4, TypeScript 2.0.3
Create project
1. Create the folder: angular2-quickstart, start VS Code, and open the newly created folder: angular2-quickstart.
2. Under the root folder (angular2-quickstart), create the package.json file:
{ "name": "angular-quickstart", "version": "1.0.0", "scripts": { "start": "tsc && concurrently \"tsc -w\" \"lite-server\" ", "lite": "lite-server", "postinstall": "typings install", "tsc": "tsc", "tsc:w": "tsc -w", "typings": "typings" }, "license": "ISC", "dependencies": { "@angular/common": "~2.0.2", "@angular/compiler": "~2.0.2", "@angular/core": "~2.0.2", "@angular/forms": "~2.0.2", "@angular/http": "~2.0.2", "@angular/platform-browser": "~2.0.2", "@angular/platform-browser-dynamic": "~2.0.2", "@angular/router": "~3.0.2", "@angular/upgrade": "~2.0.2", "angular-in-memory-web-api": "~0.1.5", "bootstrap": "^3.3.7", "core-js": "^2.4.1", "reflect-metadata": "^0.1.8", "rxjs": "5.0.0-beta.12", "systemjs": "0.19.39", "zone.js": "^0.6.25" }, "devDependencies": { "concurrently": "^3.1.0", "lite-server": "^2.2.2", "typescript": "^2.0.3", "typings": "^1.4.0" } }
3. Under the root folder (angular2-quickstart), create the tsconfig.json file :
{ "compilerOptions": { "target": "es5", "module": "commonjs", "moduleResolution": "node", "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "removeComments": false, "noImplicitAny": false } }
4. In the root folder (angular2-quickstart), create the typings.json file:
{ "globalDependencies": { "core-js": "registry:dt/core-js#0.0.0+20160725163759", "jasmine": "registry:dt/jasmine#2.2.0+20160621224255", "node": "registry:dt/node#6.0.0+20160909174046" } }
5. In the root folder (angular2-quickstart), create systemjs. config.js (JavaScript script) file:
/** * System configuration for Angular samples * Adjust as necessary for your application needs. */ (function(global) { System.config({ paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { // our app is within the app folder app: 'app', // angular bundles '@angular/core': 'npm:@angular/core/bundles/core.umd.js', '@angular/common': 'npm:@angular/common/bundles/common.umd.js', '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js', '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js', '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js', '@angular/http': 'npm:@angular/http/bundles/http.umd.js', '@angular/router': 'npm:@angular/router/bundles/router.umd.js', '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js', // other libraries 'rxjs': 'npm:rxjs', 'angular-in-memory-web-api': 'npm:angular-in-memory-web-api', }, // packages tells the System loader how to load when no filename and/or no extension packages: { app: { main: './main.js', defaultExtension: 'js' }, rxjs: { defaultExtension: 'js' }, 'angular-in-memory-web-api': { main: './index.js', defaultExtension: 'js' } } }); })(this);
File structure:
|_ angular2-quickstart |_ app | |_ app.component.ts | |_ main.ts |_ node_modules ... |_ typings ... |_ index.html |_ package.json |_ tsconfig.json |_ typings.json
Install dependency packages (the most critical step)
Use the npm command to install the dependent packages listed in package.json. In the command line cmd window, enter: cd angular2-quickstart, enter the angular2-quickstar folder, and enter the following command:
npm install
Create a TypeScript application Procedure
1. In VS Code, create the app subfolder under the root folder (angular2-quickstart).
2. In the sub-app folder, create the TypeScript file app.module.ts:
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppComponent } from './app.component'; @NgModule({ imports: [ BrowserModule ], declarations: [ AppComponent ], bootstrap: [ AppComponent ] }) export class AppModule { }
3. In the sub-app folder, create the TypeScript file app.component.ts:
import { Component } from '@angular/core'; @Component({ selector: 'my-app', template: '<h1 id="我的第一个-nbsp-AngularJS-nbsp-nbsp-应用程序">我的第一个 AngularJS 2 应用程序</h1>' }) export class AppComponent { }
4. In the sub-app folder, create the TypeScript file main.ts:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { AppModule } from './app.module'; const platform = platformBrowserDynamic(); platform.bootstrapModule(AppModule);
5. In the root folder (angular2-quickstart), create the html file index.html:
<html> <head> <title>Angular QuickStart</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="styles.css"> <!-- 1. Load libraries --> <!-- Polyfill(s) for older browsers --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.js"></script> <script src="node_modules/reflect-metadata/Reflect.js"></script> <script src="node_modules/systemjs/dist/system.src.js"></script> <!-- 2. Configure SystemJS --> <script src="systemjs.config.js"></script> <script> System.import('app').catch(function(err) { console.error(err); }); </script> </head> <!-- 3. Display the application --> <body> <my-app>Loading...</my-app> </body> </html>
6. In the root folder (angular2-quickstart), create the css file styles.css:
/* Master Styles */ h1 { color: #369; font-family: Arial, Helvetica, sans-serif; font-size: 250%; } h2, h3 { color: #444; font-family: Arial, Helvetica, sans-serif; font-weight: lighter; } body { margin: 2em; }
Configuration application
1. In VS Code, create a .vscode subfolder under the root folder (angular2-quickstart).
2. In the .vscode subfolder, create the settings.json file:
// 将设置放入此文件中以覆盖默认值和用户设置。 { "typescript.tsdk": "node_modules/typescript/lib", // ts 项目, 隐藏 .js 和 .js.map 文件 "files.exclude": { "node_modules": true, "**/*.js": { "when": "$(basename).ts" }, "**/*.js.map": true } }
3. In the .vscode subfolder, create the tasks.json file:
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "0.1.0", "command": "cmd", "isShellCommand": true, "showOutput": "always", "args": ["/C npm start"] }
Run the application. After the configuration is completed, press Ctrl Shift B to compile. The program will compile Typescript into Javascript, start a lite-server at the same time, and load the index.html we wrote. Display: My first Angular 2 application
#The above is what I compiled for everyone. I hope it will be helpful to everyone in the future. .
Related articles:
How to use Redux in React projects (detailed tutorial)
How to implement automatic numerical increase in JavaScript
How to use Swiper to implement pager usage
How to use Swiper to implement page image carousel
The above is the detailed content of How to develop AngularJS 2 applications using the VS Code editor. For more information, please follow other related articles on the PHP Chinese website!

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

Python is more suitable for data science and machine learning, while JavaScript is more suitable for front-end and full-stack development. 1. Python is known for its concise syntax and rich library ecosystem, and is suitable for data analysis and web development. 2. JavaScript is the core of front-end development. Node.js supports server-side programming and is suitable for full-stack development.

JavaScript does not require installation because it is already built into modern browsers. You just need a text editor and a browser to get started. 1) In the browser environment, run it by embedding the HTML file through tags. 2) In the Node.js environment, after downloading and installing Node.js, run the JavaScript file through the command line.

How to send task notifications in Quartz In advance When using the Quartz timer to schedule a task, the execution time of the task is set by the cron expression. Now...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor