当测试运行Angular2 Todo App时的笔记

以下是在Angular的Youtube频道上介绍的Angular2 TODO应用程序的操作笔记,记录了我尝试运行该应用程序的经历。截止到2015/2/16,这是最新的信息。

安装

首先要获取Angular2。

$ git clone https://github.com/angular/angular.git
$ cd angular
$ npm install

由于在安装依赖库时使用了node-gyp导致了许多错误,尝试将node的版本更改为0.10.x然后再次运行。

$ nodebrew install-binary v0.10.36
fetch: http://nodejs.org/dist/v0.10.36/node-v0.10.36-darwin-x64.tar.gz
######################################################################## 100.0%
Install successful

$ nodebrew use v0.10.36
use v0.10.36

虽然出现了一些警告,但似乎进展顺利。同时安装了gulp和protractor。

$ npm install -g gulp
$ npm install -g protractor
$ webdriver-manager update

请根据以下内容构建。

$ gulp build

Dart SDK不可用。跳过任务:build.dart出现,但忽略之。
请确认/angular/dist/js/dev目录是否已存在。

$ ls -l dist/js/dev
total 0
drwxr-xr-x 8 272  2 17 00:28 es5
drwxr-xr-x 7 238  2 17 00:28 es6

es5和es6都可用,但是在2月16日的README.md文件中只有一个选项。

ln -s ~/angular/dist/js/dev ng

根据pull/3的方式,特定子目录进行符号链接。路径根据需要自行修改。

$ git clone https://github.com/davideast/ng2do.git
$ cd ng2do
$ ln -s ~/angular/dist/js/dev/es5 ng

服务器启动

启动服务器,并从浏览器访问http://localhost:8000。

$ python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...

不动。
控制台显示以下错误。

"Error during instantiation of Token(AppComponentAnnotatedType)!. ORIGINAL ERROR: TypeError: TemplateConfig is not a constructor

似乎是因为pull/5上升了的原因。将TemplateConfig更改为Template。

import {Component, Template, bootstrap, Foreach} from 'angular2/angular2';
  ]
})
@Template({
  url: '/todo.html',
  directives: [Foreach]
})

修正了两处,结果在Chrome上运行正常。(但在Firefox上无法运行)

广告
将在 10 秒后关闭
bannerAds