运行我的应用时,我收到以下错误:
src / app / components / user.components.ts(33,11):错误TS7006:参数' Hobbi'隐含地有一个“任何”的类型。 [0] src / app / components / user.components.ts(37,14):错误TS7006:参数' i'隐含地有一个“任何”的类型。
这是我的代码:
@Component({
moduleId : module.id,
selector: 'user',
templateUrl: `user.components.html`,
})
export class UserComponent {
name : string;
email : String;
address: address;
hobbies : string[];
ShowHobbies : boolean;
constructor(){
this.name = 'Ratheesh';
this.email = 'babu.ratheesh@7nodes.com';
this.address={
street : 'Near Assisi Lane',
city: 'Ernakulam',
country : 'India'
}
this.hobbies = ['Reading', 'sports' , 'music']
this.ShowHobbies = false;
}
ToggleHobbies(){
// console.log('SHow');
if(this.ShowHobbies == true) {
this.ShowHobbies = false;
}else{
this.ShowHobbies = true;
}
}
addHobby(Hobbi){
this.hobbies.push(Hobbi);
}
deleteHobby(i){
this.hobbies.splice(i, 1);
}
}
interface address {
street : string;
city: string;
country :string;
}
答案 0 :(得分:0)
您需要将该类型传递为 any
,
addHobby(Hobbi:any){
this.hobbies.push(Hobbi);
}