https://github.com/PatrickJS/angular-websocket
在我的简单应用程序库。
我的AngularJS版本是:
Angular CLI: 11.2.0
Node: 14.15.5
OS: darwin x64
Angular: 11.2.0
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1102.0
@angular-devkit/build-angular 0.1102.0
@angular-devkit/core 11.2.0
@angular-devkit/schematics 11.2.0
@schematics/angular 11.2.0
@schematics/update 0.1102.0
rxjs 6.6.3
typescript 4.1.5
I'm not using bower for managing packages so to install the websocket library I use :
npm install angular-websocket --save
which installs successfully.
To use the web socket library I declare a new component :
import { Component2 } from 'angular-websocket'
@Component2({
selector: 'courses',
template: `
<h2>{{ title }}</h2>
<ul>
<li *ngFor="let course of courses">
{{ course }}
</li>
</ul>
`
})
Error: src/app/courses.component.ts:5:28 - error TS7016: Could not find a declaration file for module 'angular-websocket'. '/Users/hello-world/node_modules/angular-websocket/dist/angular-websocket.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/angular-websocket` if it exists or add a new declaration (.d.ts) file containing `declare module 'angular-websocket';`
5 import { Component2 } from 'angular-websocket'
执行后
npm i --save-dev @types/angular-websocket
executing ng serve
:
Error: src/app/courses.component.ts:5:10 - error TS2305: Module '"../../node_modules/@types/angular-websocket"' has no exported member 'Component2'.
5 import { Component2 } from 'angular-websocket'
如何导入和使用带有组件的WebSocket库?