简体   繁体   中英

Typescript error TS1005: '=' expected

I keep getting this error when compiling my app. 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.

here's my code:

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;
        })
    }
}

I've read it could be because of updated syntax from TS and did updated it to latest 2.1.0 version and still got the error.

Anyone can help me on this?

Looks like you need a type specifier for those lines, something like:

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

If you have the more explicit types available, use those instead.

EDIT

As noted in comments on the question, using any can have its own issues. In that case, you will need to find the correct type of each of these variables and replace any with that. One possibility is product but without seeing more of the code it's difficult to tell.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM