0
當編譯角2應用程式一些誤差面臨角2編譯錯誤
應用/組件/ user.component.ts(45,11):錯誤TS7006:參數「愛好」隱含有一個「任意」類型的。 app/components/user.component.ts(49,14):錯誤TS7006:參數'i'隱式具有'any'類型。
import { Component } from '@angular/core';
import {PostService} from '../services/post.service';
@Component({
moduleId:module.id,
selector: 'user',
templateUrl: 'user.component.html',
providers:[PostService]
})
export class UserComponent {
name: string;
email: string;;
address:address;
hobbies:string[];
showHobbies:boolean;
posts:Post[]
constructor(private postService : PostService){ //everytime load
//console.log("hear it is constructor....");
this.name = 'Jck';
this.email = '[email protected]';
this.address = {
street: 'Saga',
city: 'SOP',
state: 'GuO'
}
this.hobbies = ['MUSIC','Cricket'];
this.showHobbies=false;
this.postService.getPost().subscribe(posts => {
//console.log(posts);
this.posts =posts;
});
}
toggleHobbies(){
//console.log("toggleHobbies >>>");
if(this.showHobbies){
this.showHobbies=false;
}else{
this.showHobbies=true;
}
}
addHobby(hobby){
//console.log("add hobby >>"+hobby);
this.hobbies.push(hobby);
}
deleteHobby(i){
//console.log("deleteHobby i >>"+i);
this.hobbies.splice(i,1)
}
}
interface address{
street : string;
city : string;
state : string;
}
interface Post{
id:number;
title:string;
body:string;
}
感謝您的解決方案。 –