我寫了一篇關於問題的新文章以提供更多詳細信息。Ionic 2:「屬性號」在類型'typeof'上不存在
我嘗試在我的離子2項目,創建一個類,我用這個代碼:
import { Component } from '@angular/core';
@Component({
templateUrl: 'field.html'
})
export class test {
x : number;
constructor(x : number){
this.x = x;
}
}
我想在我的其他組件來使用它。它在我的終端中用「離子服務」進行編譯時起作用。但是,當我嘗試在我的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! [email protected] build: `ionic-app-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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
我不明白爲什麼。首先我在提供者文件上嘗試相同的代碼,但同樣的問題。
有人有什麼想法嗎?
而不是這樣做,只需使用'constructor(private x:number){// ...}'。通過這樣做,您不需要在組件中聲明'private'屬性,因爲typescript正在爲您聲明它。 – sebaferreras
好的,謝謝我改變了這一點。但這不是解決方案。 :) –
當然,這就是爲什麼它只是一個評論,而不是答案:) – sebaferreras