我在编译我的应用程序时不断收到此错误。 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/