繁体   English   中英

类型上不存在属性

[英]Property does not exist on type

我正在使用 Ionic2 和 Angular2 进行一个项目。 尝试运行ionic serve ,检索的数据没有任何错误。 但是,当尝试在 ios 上测试并运行ionic build ios ,我收到以下编译时错误,该属性不存在。

有没有其他人遇到过这个问题?

我很感激任何建议。

家.ts

import { Component } from '@angular/core';
import { ProfileService } from './profile.service';

@Component({
    selector: 'home',
    templateUrl: 'home.html',
    providers: [ProfileService]
})
export class HomePage {

    constructor(public d: HomeService){
        this.loadData();
    }

    loadData() {
     this.d.fbPromise.then( (FB) =>    this.data.getData(FB)).then(response => {
         this.data = response;
     });
   }
}

主页.html

<ion-header>
    <ion-navbar>
        <ion-title>Home</ion-title>
    </ion-navbar>
</ion-header>

<ion-content>

    <div class="profile-content" padding>
        <div class="content-header">
            <h2 class="name">{{ this.data.name }}</h2>


        <div class="interests-content">
            <h3>interests</h3>

            <span *ngFor="let interest of this.data.interests" >
                {{ interest.title }} : {{interest.name}}
            </span>
        </div>
    </div>
</ion-content>

编译时错误:

[10:10:18]  Error: Error at /Users/zzz/Sites/angular-app/Flah/.tmp/pages/home/home.ngfactory.ts:330:47 
[10:10:18]  Property 'name' does not exist on type 'HomeService'. 
[10:10:18]  Error at /Users/zzz/Sites/angular-app/Flah/.tmp/pages/home/profhomeile.ngfactory.ts:349:72 
[10:10:18]  Error at /Users/zzz/Sites/angular-app/Flah/.tmp/pages/home/phomerofile.ngfactory.ts:354:72 
[10:10:18]  Property 'interests' does not exist on type 'HomeService'. 
[10:10:18]  ngc failed 
[10:10:18]  ionic-app-script task: "build" 
[10:10:18]  Error: Error 

不要在视图绑定中使用this

{{ this.data.name }}<

应该是

{{ data.name }}<

在依赖注入中更改导入的服务文件的名称

从 './profile.service' 导入 { ProfileService };

构造函数(公共 d:ProfileService ){}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM