0

angularjs の 1 から 2 へのアップグレード チュートリアル ( Angular 1 upgrade ) と phonecat コードベースの例に取り組んでいます。typescript と前述のすべての依存関係をインストールした後、関数パラメーター入力に type :booleanを追加すると、chrome が「Uncaught SyntaxError: Unexpected token :」で実行に失敗し、checkmarkFilterProvider が連続して作成されず、コンポーネントへのプロバイダーの注入に失敗します。

(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 scripts -> start を参照)。

スクリプト実行後の ./app フォルダーには、*.js および *.map.js ファイルがコンパイルされています。 ここに画像の説明を入力

4

1 に答える 1