angular - 属性在类型上不存在

标签 angular typescript ionic2

我正在使用 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 

最佳答案

不要在 View 绑定(bind)中使用this

{{ this.data.name }}<

应该是

{{ data.name }}<

关于angular - 属性在类型上不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40592029/

相关文章:

android - Cordova 构建 android 显示 "You have not accepted the license agreements of the following SDK components"

ionic-framework - 通过更新 google-services 插件的版本来解决版本冲突 | ionic

angular - RouterModule.forRoot 调用了两次

typescript bool 函数必须返回一个值

css - 如何将表格推到键盘上方?

node.js - 语法错误 : Cannot find name 'setImmediate'

javascript - Ionic 2 - 隐藏子页面上的标签

Angular找不到变量缓存

javascript - 在 Angular2 中添加动态属性

angular - Ionic2 Ion-select 没有 OK 和 Cancel