angular - typescript 错误 TS1005 : '=' expected

我在编译我的应用程序时不断收到此错误。 TS v2.0.3

app/components/profile.component.ts(13,12): error TS1005: '=' expected.
app/components/profile.component.ts(14,13): error TS1005: '=' expected.
app/components/profile.component.ts(16,10): error TS1005: '=' expected.

这是我的代码:

import { Component } from '@angular/core';

import { apiService } from '../services/api.service';

import 'rxjs/add/operator/map';

@Component({
    moduleId: module.id,
    selector: 'profile',
    templateUrl: './profile.component.html'
})
export class ProfileComponent{
    product[];
    products[];
    productTitle:string;
    first[];

    constructor(private _apiService:apiService){
        this._apiService.getProduct().subscribe(product => {
            //console.log(product.result.products);
            this.product = product.result.products[0];
        })
    }
    searchProd() {
        this._apiService.updateTitle(this.productTitle);
        this._apiService.getProduct().subscribe(productTitle => {
            //console.log(productTitle.result.products);
            this.first = productTitle.result.products[0];
            this.products = productTitle.result.products;
        })
    }
}

我读过它可能是因为 TS 更新了语法并且确实将其更新到最新的 2.1.0 版本但仍然出现错误。

谁能帮我解决这个问题?

最佳答案

看起来您需要为这些行添加一个类型说明符,例如:

product:any[];
products:any[];
first:any[];

如果您有更明确的可用类型,请改用它们。

编辑

如问题评论中所述,使用 any 可能有其自身的问题。在这种情况下,您将需要找到每个变量的正确类型并将 any 替换为该类型。一种可能性是 product,但如果没有看到更多代码,就很难判断。

关于angular - typescript 错误 TS1005 : '=' expected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39988648/

相关文章:

erlang - 有什么方法可以浏览 erlang 术语存储 (ETS)

r - 如何在列表列上应用一个函数并在 dplyr 和 purrr 中返回另一个函数?

python - Django 选择和字典

python - 检查 Python 中两个字符串中的常用字母是否位于同一位置?

android-instrumentation - AndroidJUnitRunner + Act

scala - 如何对spark Dataframe进行合并操作?

java - 当 PoolingHttpClientConnectionManager 中的 Max

sql-server - TSQL 触发器而不是插入

Groovy - 无法在注释中使用静态最终字符串

scala - 隐式是私有(private)的吗?