最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

利用VS Code開發(fā)你的第一個(gè)AngularJS 2應(yīng)用程序

 更新時(shí)間:2017年12月15日 11:01:09   作者:俊先  
這篇文章主要給大家介紹了關(guān)于利用VS Code如何開發(fā)你的第一個(gè)AngularJS 2應(yīng)用程序的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友下面來一起看看吧。

前言

之前已經(jīng)給大家介紹了Angular2開發(fā)環(huán)境搭建教程之VS Code,本文將詳細(xì)介紹利用VS Code如何開發(fā)AngularJS2應(yīng)用程序的相關(guān)內(nèi)容,分享出來供大家參考學(xué)習(xí),下面話不多說了,來一起看看詳細(xì)的介紹吧。

運(yùn)行環(huán)境:

1、Windows 10

2、Node 6.7.0

3、npm 3.10.8

4、TypeScript 2.0.3

創(chuàng)建項(xiàng)目

1、創(chuàng)建文件夾:angular2-quickstart,啟動(dòng)VS Code,打開剛創(chuàng)建的文件夾:angular2-quickstart。

2、在根文件夾(angular2-quickstart)下,創(chuàng)建package.json文件:

{
 "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、在根文件夾(angular2-quickstart)下,創(chuàng)建tsconfig.json文件:

{
 "compilerOptions": {
 "target": "es5",
 "module": "commonjs",
 "moduleResolution": "node",
 "sourceMap": true,
 "emitDecoratorMetadata": true,
 "experimentalDecorators": true,
 "removeComments": false,
 "noImplicitAny": false
 }
}

4、在根文件夾(angular2-quickstart)下,創(chuàng)建typings.json文件:

{
 "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、在根文件夾(angular2-quickstart)下,創(chuàng)建systemjs.config.js(JavaScript腳本)文件:

/**
 * 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);

文件結(jié)構(gòu):

|_ angular2-quickstart
|_ app
| |_ app.component.ts
| |_ main.ts
|_ node_modules ...
|_ typings ...
|_ index.html
|_ package.json
|_ tsconfig.json
|_ typings.json

安裝依賴包(最關(guān)鍵一步

使用 npm 命令來安裝 package.json 中列出的依賴包。在命令行 cmd 窗口,輸入:cd angular2-quickstart,進(jìn)入angular2-quickstar文件夾下,輸入下列命令:

npm install

創(chuàng)建TypeScript應(yīng)用程序

1、在VS Code中,在根文件夾(angular2-quickstart)下,創(chuàng)建app子文件夾。

2、在子app文件夾下,創(chuàng)建TypeScript文件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、在子app文件夾下,創(chuàng)建TypeScript文件app.component.ts:

import { Component } from '@angular/core';
@Component({
 selector: 'my-app',
 template: '<h1>我的第一個(gè) AngularJS 2 應(yīng)用程序</h1>'
})
export class AppComponent { }

4、在子app文件夾下,創(chuàng)建TypeScript文件main.ts:

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);

5、在根文件夾(angular2-quickstart)下,創(chuàng)建html文件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、在根文件夾(angular2-quickstart)下,創(chuàng)建css文件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;
}

配置應(yīng)用程序

1、在VS Code中,在根文件夾(angular2-quickstart)下,創(chuàng)建.vscode子文件夾。

2、在.vscode子文件夾下,創(chuàng)建settings.json文件:

// 將設(shè)置放入此文件中以覆蓋默認(rèn)值和用戶設(shè)置。
{
 "typescript.tsdk": "node_modules/typescript/lib",
 // ts 項(xiàng)目, 隱藏 .js 和 .js.map 文件
 "files.exclude": {
  "node_modules": true,
  "**/*.js": { "when": "$(basename).ts" },
  "**/*.js.map": true
 }
}

3、在.vscode子文件夾下,創(chuàng)建tasks.json文件:

{
 // 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"]
}

運(yùn)行應(yīng)用程序至此,配置完畢,按 Ctrl + Shift + B 編譯,程序?qū)?huì)將Typescript編譯成 Javascript ,同時(shí)啟動(dòng)一個(gè) lite-server, 加載我們編寫的index.html。 顯示:我的第一個(gè) Angular 2 應(yīng)用程序

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問大家可以留言交流,謝謝大家對(duì)腳本之家的支持。

參考資料:

相關(guān)文章

  • AngularJS 路由詳解和簡(jiǎn)單實(shí)例

    AngularJS 路由詳解和簡(jiǎn)單實(shí)例

    本文主要介紹AngularJS 路由,這里整理了相關(guān)資料進(jìn)行詳細(xì)介紹,并附實(shí)例代碼和實(shí)現(xiàn)效果圖,有需要的小伙伴可以參考下
    2016-07-07
  • indexedDB bootstrap angularjs之 MVC DOMO (應(yīng)用示例)

    indexedDB bootstrap angularjs之 MVC DOMO (應(yīng)用示例)

    這篇文章主要介紹了indexedDB bootstrap angularjs之 MVC DOMO (應(yīng)用示例)的相關(guān)資料,需要的朋友可以參考下
    2016-06-06
  • AngularJS包括詳解及示例代碼

    AngularJS包括詳解及示例代碼

    本文主要介紹AngularJS包括的基礎(chǔ)知識(shí),這里整理了相關(guān)資料并附示例代碼和實(shí)現(xiàn)效果圖,有需要的小伙伴可以參考下
    2016-08-08
  • 詳解AngularJS 路由 resolve用法

    詳解AngularJS 路由 resolve用法

    本篇文章主要介紹了AngularJS 路由 resolve用法,詳細(xì)的介紹了resolve用法,想要了解resolve用法的朋友可以了解一下
    2017-04-04
  • AngularJS實(shí)現(xiàn)網(wǎng)站換膚實(shí)例

    AngularJS實(shí)現(xiàn)網(wǎng)站換膚實(shí)例

    這篇文章主要為大家詳細(xì)介紹了AngularJS實(shí)現(xiàn)網(wǎng)站換膚的簡(jiǎn)單實(shí)例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • Angular 4中如何顯示內(nèi)容的CSS樣式示例代碼

    Angular 4中如何顯示內(nèi)容的CSS樣式示例代碼

    這篇文章主要給大家介紹了關(guān)于Angular 4中如何顯示內(nèi)容的CSS樣式的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-11-11
  • Angular 2父子組件數(shù)據(jù)傳遞之@Input和@Output詳解(下)

    Angular 2父子組件數(shù)據(jù)傳遞之@Input和@Output詳解(下)

    這篇文章主要給大家介紹了關(guān)于Angular 2父子組件數(shù)據(jù)傳遞之@Input和@Output的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧。
    2017-07-07
  • 詳解webpack+es6+angular1.x項(xiàng)目構(gòu)建

    詳解webpack+es6+angular1.x項(xiàng)目構(gòu)建

    這篇文章主要介紹了詳解webpack+es6+angular1.x項(xiàng)目構(gòu)建, 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-05-05
  • angular和BootStrap3實(shí)現(xiàn)購物車功能

    angular和BootStrap3實(shí)現(xiàn)購物車功能

    這篇文章主要為大家詳細(xì)介紹了angular和BootStrap3實(shí)現(xiàn)購物車功能的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • Angular.js中angular-ui-router的簡(jiǎn)單實(shí)踐

    Angular.js中angular-ui-router的簡(jiǎn)單實(shí)踐

    本篇文章主要介紹了Angular.js中angular-ui-router的簡(jiǎn)單實(shí)踐,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-07-07

最新評(píng)論

奈曼旗| 隆化县| 永靖县| 遂宁市| 临朐县| 基隆市| 获嘉县| 文成县| 大理市| 刚察县| 定边县| 金阳县| 海伦市| 威海市| 随州市| 龙山县| 中牟县| 正阳县| 积石山| 双鸭山市| 修水县| 北碚区| 昭通市| 三原县| 安宁市| 丰都县| 兴安县| 东平县| 北辰区| 翁源县| 高青县| 枣强县| 新津县| 罗源县| 垣曲县| 耿马| 广州市| 任丘市| 衡山县| 朔州市| 达州市|