我想在我的 Angular 11 应用程序中使用 Google One Tap。按照文档,我添加<script async defer src="https://accounts.google.com/gsi/client"></script>到我的 html 中,然后在我的 中使用以下代码app.component.html:
<div id="g_id_onload"
data-client_id="MY_GOOGLE_CLIENT_ID"
data-callback="handleCredentialResponse",
data-cancel_on_tap_outside="false">
</div>
Run Code Online (Sandbox Code Playgroud)
弹出窗口工作正常,但我似乎无法登录。如果我handleCredentialResponse在 中创建一个函数app.component.ts,则会收到以下错误:[GSI_LOGGER]: The value of 'callback' is not a function. Configuration ignored.
如果我尝试使用 JavaScript API,Typescript 会抛出以下错误:Property 'accounts' does not exist on type 'typeof google'
我应该怎么做才能在 Angular 中使用 Google One Tap?
运行时出现以下错误npm build --prod:
Error: budgets: initial exceeded maximum budget. Budget 1.00 MB was not met by 500.42 kB with a total of 1.49 MB.
我也收到此警告:
Warning: C:\Users\PATH_TO_FILE\socket.service.ts depends on 'socket.io-client'. CommonJS or AMD dependencies can cause optimization bailouts. For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
我还导入了很多 Angular Material 模块。这是我的app.module.ts(这是我整个项目中唯一的模块):
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FontAwesomeModule } from …Run Code Online (Sandbox Code Playgroud)