2017-01-10 22 views
0

角度コンパイル時に2は、いくつかのエラーが角度2コンパイルエラー

APP /コンポーネント/ 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; 
} 

答えて

2

あなたの機能addHobbydeleteHobbyの引数の型を定義するのを忘れ:

addHobby(hobby: string){ 
    //console.log("add hobby >>"+hobby); 
    this.hobbies.push(hobby); 
} 
deleteHobby(i: number){ 
    //console.log("deleteHobby i >>"+i); 
    this.hobbies.splice(i, 1) 
} 
+0

その解決のための感謝を。 –