我試圖在我的ionic2應用程序中實現谷歌身份驗證。我需要它在瀏覽器中工作。所以,我安裝:Typescript錯誤,無法找到名稱'gapi',transpile失敗
npm install --save @types/gapi
npm install --save @types/gapi.auth2
有兩個警告:
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected]^1.0.0 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
在node_modules文件夾我有GAPI和gapi.auth2文件夾,但我有打字稿錯誤:無法找到名爲 'GAPI',transpile失敗。
我安裝
npm install typings -g
typings install dt~gapi --global --save
typings install dt~gapi.auth2 --global --save
仍然有同樣的錯誤:無法找到名爲 'GAPI',transpile失敗
我的代碼:
auth2: any;
login() {
gapi.load('auth2',() => {
this.auth2 = gapi.auth2.init({
client_id: 'xxxxxxxxx.apps.googleusercontent.com',
scope: 'https://www.googleapis.com/auth/userinfo.email'
});
});
};
我的package.json:
"@angular/core": "2.2.1",
"ionic-angular": "2.0.0-rc.4",
"ionic-native": "2.2.11",
"rxjs": "5.0.0-beta.12",
"typescript": "2.0.9"
謝謝你,爲我工作! 請注意,在較新版本的angular-cli中,這些編輯的正確文件可能是tsconfig.app.json – Willy