角度2中的TS1005错误

时间:2017-01-05 18:54:10

标签: angular

我刚开始从ng-2书中学习Angular 2。正在构建类似于reddit的初始应用程序但由于此错误而无法编译。我有这个错误:

app.ts(57,13): error TS1005: ';' expected.
[0] app.ts(58,12): error TS1005: ';' expected.
[0] app.ts(59,13): error TS1005: ';' expected.

寻找解决方案,从而更新了我的typescrypt版本,但错误仍然存​​在。

Package.json

{
  "name": "ng-book2-reddit",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "clean": "rm -f ./*.js; rm -f ./*.js.map; rm -f ./intermediates/*.js; rm -f ./intermediates/*.js.map",
    "tsc": "./node_modules/.bin/tsc",
    "tsc:w": "./node_modules/.bin/tsc -w",
    "serve": "./node_modules/.bin/live-server --host=localhost --port=8080 .",
    "go": "concurrent \"npm run tsc:w\" \"npm run serve\" "
  },
  "license": "ISC",
  "dependencies": {
    "@angular/common": "2.4.1",
    "@angular/compiler": "2.4.1",
    "@angular/core": "2.4.1",
    "@angular/forms": "2.4.1",
    "@angular/http": "2.4.1",
    "@angular/platform-browser": "2.4.1",
    "@angular/platform-browser-dynamic": "2.4.1",
    "@angular/router": "3.4.1",
    "@angular/router-deprecated": "2.0.0-rc.2",
    "core-js": "2.4.1",
    "es6-shim": "0.35.2",
    "reflect-metadata": "0.1.9",
    "rxjs": "5.0.2",
    "systemjs": "0.19.41",
    "ts-helpers": "1.1.2",
    "tslint": "4.2.0",
    "typescript": "2.1.4",
    "typings": "2.1.0",
    "zone.js": "0.7.4"
  },
  "devDependencies": {
    "concurrently": "3.1.0",
    "live-server": "1.1.0",
    "typescript": "2.1.4"
  }
}

App.ts

...
class ArticleComponent {
    votes: number;
    title: string;
    link: string;

    constructor() {
        this.title: 'Angular 2';
        this.link: 'http://angular.io';
        this.votes: 10;
    }

    voteUp() {
        this.votes += 1;
        return false;
    }

    voteDown() {
        this.votes -= 1;
        return false;

    }

}
...

如何解决错误?

1 个答案:

答案 0 :(得分:0)

this.title: 'Angular 2';
this.link: 'http://angular.io';
this.votes: 10;

应该是

this.title= 'Angular 2';
this.link= 'http://angular.io';
this.votes= 10;

:用于类型分配。