惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - oldkingsir

angularjs2 学习笔记(六) Form angularjs2 学习笔记(五) http服务 angularjs2 学习笔记(三) 服务 angularjs2 学习笔记(四) 路由 angularjs2 学习笔记(二) 组件 Silverlight中利用MEF进行模块注入时注入错误问题分析 prism中ImportingConstructor构造注入时的参数匹配 解决Prism的EventAggregator的事件订阅错误 解决Prism中Region的GetView不起作用问题 Prism中在Region中注入匹配问题 想找一个专业一点的silverlight开发的群,谁知道啊! 在Prism中利用Region的对ContentControl的自动充填问题 silverlight 学习笔记 (九):Prism与MVVM模式在silverlight中的应用 由csdn搬家来此 silverlight 学习笔记 (八):Prism中MEF的初步认识 silverlight 学习笔记 (七):Prism的第一个应用 vs2010中使用odac for .net的连接配置 Silverlight中对WCF RIA 的异步调用的同步处理解决办法 silverlight 学习笔记导航
angularjs2 学习笔记(一) 开发环境搭建
oldkingsir · 2016-05-16 · via 博客园 - oldkingsir

开发环境,vs2013 update 5,win7 x64,目前最新angular2版本为beta 17

第一步:安装node.js

安装node.js(https://nodejs.org/en/),为的是能够使用npm获得angular2.0的开发包

验证是否安装成功

cmd下输入 node -v

npm -v

第二步:在vs2013上安装typescript

安装完成后在项目中可以添加typescript项目了,并且在项目属性栏中会有typescript页

第三步:创建项目

可以将没用的都删除

第四步:添加package.json文件用于获取angularjs2包及依赖项

编辑文件,添加内容

{

   "name": "angular2demo",

   "version": "1.0.0",

   "license": "ISC",

   "dependencies": {

     "angular2": "2.0.0-beta.17",

     "systemjs": "0.19.27",

     "es6-promise": "^3.2.1",

     "es6-shim": "^0.35.0",

     "reflect-metadata": "0.1.2",

     "rxjs": "5.0.0-beta.6",

     "zone.js": "0.6.12"

   },

   "devDependencies": {

     "typescript": "^1.7.5"

   }

}

对于所需要的包可通过npm查询最新版本,如

npm info angular2

下一步:配置package.config使用npm获取angular2相关包

在右键项目,选择power command 下的cmd下执行npm install

如果出现错误,需要安装“tsd”包的话,需要执行

npm install tsd -g

然后再进行安装

安装完成后

下一步:创建个人应用,注意在入口处需要添加browser.d.ts引用

新建一个app目录,并添加app.component.ts,main.ts

App.component.ts中添加angularjs模块

import {Component} from 'angular2/core';
 
@Component({
    selector: 'angular2-demo',
    template: '<h1>这是我的第一个应用</h1>'
})
export class AppComponent { }
此时编译会出现错误“connot find promise”等

这时需要在App.component.ts顶部添加引用

///<reference path="../node_modules/angular2/typings/browser.d.ts"/>

完整如下:

///<reference path="../node_modules/angular2/typings/browser.d.ts"/>

import {Component} from 'angular2/core';

@Component({

    selector: 'angular2-demo',

    template: '<h1>这是我的第一个应用</h1> <h2>太神奇了</h2>'

})

export class AppComponent { }

 

在mian.ts中添加app模块

import {bootstrap}    from 'angular2/platform/browser'
import {AppComponent} from './app.component'
 
bootstrap(AppComponent);
 

下一步:添加index.html页

<html>
<head>
    <title>Angular 2 Demo</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
 
    <!-- 1. Load libraries -->
    <!-- IE required polyfills, in this exact order -->
    <script src="node_modules/es6-shim/es6-shim.min.js"></script>
    <script src="node_modules/systemjs/dist/system-polyfills.js"></script>
 
    <script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
    <script src="node_modules/systemjs/dist/system.src.js"></script>
    <script src="node_modules/rxjs/bundles/Rx.js"></script>
    <script src="node_modules/angular2/bundles/angular2.dev.js"></script>
 
    <!-- 2. Configure SystemJS -->
    <script>
        System.config({
            packages: {
                app: {
                    format: 'register',
                    defaultExtension: 'js'
                }
            }
        });
        System.import('app/main').then(null, console.error.bind(console));
    </script>
 
</head>
 
<!-- 3. Display the application -->
<body>
    <angular2-demo>Loading...</angular2-demo>
</body>
 
</html>
 

下一步:更改typescript编译选项,修改项目文件

如果此时编译会出现错误,错误信息“connot find name promise"

此时需要修改项目属性,如下选择system,同时修改项目文件在PropertyGroup中的debug和release中同时添加

<TypeScriptEmitDecoratorMetadata>true</TypeScriptEmitDecoratorMetadata>

    <TypeScriptModuleResolution>Node</TypeScriptModuleResolution>

    <TypeScriptExperimentalDecorators>true</TypeScriptExperimentalDecorators>

 

最后,文件编译成功,在app下的main.ts和app.component.ts会自动编译成.js文件,终于在浏览器上看到了第一个angular2的页面了,这中间好多坑,实验了很多个版本,各个版本出现的错误都不是一样的,毕竟还是beta版,先拿这个版本学习了!