【问题标题】:src/app/components/user.components.ts(37,14): error TS7006: Parameter 'i' implicitly has an 'any' typesrc/app/components/user.components.ts(37,14): 错误 TS7006: 参数 'i' 隐式具有 'any' 类型
【发布时间】:2017-03-18 09:33:36
【问题描述】:

运行我的应用时,我收到以下错误:

src/app/components/user.components.ts(33,11):错误 TS7006:参数“Hobbi”隐含地具有“任何”类型。 [0] src/app/components/user.components.ts(37,14): 错误 TS7006: 参数 'i' 隐式具有 'any' 类型。

这是我的代码:

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

【问题讨论】:

    标签: angular


    【解决方案1】:

    您需要将类型传递为any

     addHobby(Hobbi:any){
            this.hobbies.push(Hobbi);
     }
    

    【讨论】:

      猜你喜欢
      • 2020-02-02
      • 2020-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 2021-11-17
      • 2018-09-23
      • 2018-09-25
      相关资源
      最近更新 更多