javascript - ionic 2 : "Property ' number' does not exist on type 'typeof"

标签 javascript android angular typescript ionic2

我写了一篇关于问题的新帖子以提供更多详细信息。

我尝试在我的 ionic 2 项目中创建一个类,我使用以下代码:

import { Component } from '@angular/core';

@Component({
    templateUrl: 'field.html'
})

export class test {
    x : number;
    constructor(x : number){
        this.x = x;
    }
}

我想在我的其他组件中使用它。在我的终端中使用“ionic serve”编译它时它是有效的。但是当我尝试在我的 android 手机上编译时,我遇到了这个错误:

[09:54:06]  Error at C:/xampp/htdocs/AppFineMobile/.tmp/classes/fieldSpecs/test.ngfactory.ts:42:71
[09:54:06]  Property 'number' does not exist on type 'typeof
            "C:/xampp/htdocs/AppFineMobile/.tmp/classes/fieldSpecs/test"'.
[09:54:06]  ngc failed
[09:54:06]  ionic-app-script task: "build"
[09:54:06]  Error: Error

npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
npm ERR! node v7.0.0
npm ERR! npm  v3.10.8
npm ERR! code ELIFECYCLE
npm ERR! ionic-hello-world@ build: `ionic-app-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ionic-hello-world@ build script 'ionic-app-scripts build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the ionic-hello-world package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     ionic-app-scripts build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs ionic-hello-world
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls ionic-hello-world
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\xampp\htdocs\AppFineMobile\npm-debug.log

我不明白为什么。首先,我在提供程序文件上尝试了相同的代码,但出现了同样的问题。

有人知道吗?

最佳答案

当一个类被 @component 装饰时,这些类是由 Angular 的 Dependency Injection 框架创建的,它试图从构造函数参数的类型中找到提供者作为关键找到一个。

stringnumberbooleanObject 等原始类型不能用作键。我不确定为什么 ionic serve 没有失败。您可以了解有关 DI 的更多信息 here.

关于javascript - ionic 2 : "Property ' number' does not exist on type 'typeof",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41358615/

相关文章:

android - RecyclerView 项目动画,onAnimationFinished 被调用,但没有 onAnimationStarted。为什么?

android - IONIC/angular 将原点作为文件 ://in POST and PUT -Getting 403 forbidden Error from API 发送

angular - WebStorm 在具有热重载的 Ionic2 项目上长时间卡住

javascript - 如何使用 jquery validate 来防止通过菜单链接进行导航(如果表单无效)

javascript - babel 的 Playground 出现意外的前导下划线

java - 具有两次 orderByChild 条件的 Firebase 查询

java - 如何使通用布局包含在其他布局中,但在 Android 应用程序开发中动态更改通用布局内的属性?

php - Javascript 确认删除

javascript - 如何在javascript中组合具有相同键的数组中的对象?

angular - 通过抓取 ElementRef : angular2 禁用按钮