我正在研究从 1 到 2 升级教程(Angular 1 upgrade)和 phonecat 代码库示例的 angularjs。在安装 typescript 和所有提到的依赖项后,为函数参数输入添加类型:boolean会使 chrome 执行失败,并出现“Uncaught SyntaxError: Unexpected token :” checkmarkFilterProvider 连续未创建,并且 Provider 注入组件失败。
(function() {
///<reference path='../../../typings/index.d.ts' />
'use strict';
angular.
module('core').
filter('checkmark', function() {
return function(input:boolean) {
return input ? '\u2713' : '\u2718';
};
});
})();
npm run tsc -w 命令编译 .ts 文件并创建地图,但是,浏览器执行失败。
包.json
{
"name": "angular-phonecat",
"private": true,
"version": "0.0.0",
"description": "A tutorial application for AngularJS",
"repository": "https://github.com/angular/angular-phonecat",
"license": "MIT",
"dependencies": {},
"devDependencies": {
"bower": "^1.7.7",
"concurrently": "^2.1.0",
"http-server": "^0.9.0",
"jasmine-core": "^2.4.1",
"karma": "^0.13.22",
"karma-chrome-launcher": "^0.2.3",
"karma-firefox-launcher": "^0.1.7",
"karma-jasmine": "^0.3.8",
"protractor": "^3.2.2",
"shelljs": "^0.6.0",
"tsc": "^1.20150623.0",
"typescript": "^1.8.10",
"typings": "^1.0.4"
},
"scripts": {
"postinstall": "bower install",
"prestart": "npm install",
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run http\" ",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings",
"http": "http-server -a localhost -p 8000 -c-1 ./app",
"pretest": "npm install",
"test": "karma start karma.conf.js",
"test-single-run": "karma start karma.conf.js --single-run",
"preupdate-webdriver": "npm install",
"update-webdriver": "webdriver-manager update",
"preprotractor": "npm run update-webdriver",
"protractor": "protractor e2e-tests/protractor.conf.js",
}
}
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true
},
"exclude": [
"node_modules"
]
}
最后 *.ts 源文件在项目资源管理器中编译,但浏览器没有它们,正如@tadwork 指出的那样。我的配置遗漏了什么?
更新
要运行 Angular 应用程序,我从 package.json 执行 npm start 脚本,理论上应该编译 *.ts 文件并以 ./app 作为服务器源运行 http-server(请参阅 package.json 脚本 -> 开始)。