Javascript 在Angular 2中导入Socket.io客户端,获取依赖项错误
我尝试使用以下方法将Socket.io客户端添加到Angular 2应用程序中 但现在我了解了Socket.io客户端JavaScript文件的依赖性错误 下面是TypeScript文件Javascript 在Angular 2中导入Socket.io客户端,获取依赖项错误,javascript,angular,socket.io,Javascript,Angular,Socket.io,我尝试使用以下方法将Socket.io客户端添加到Angular 2应用程序中 但现在我了解了Socket.io客户端JavaScript文件的依赖性错误 下面是TypeScript文件 import { Component, OnInit,NgZone } from '@angular/core'; import { GroundService } from '../../services/ground.service'; import { Ground } from '../../../G
import { Component, OnInit,NgZone } from '@angular/core';
import { GroundService } from '../../services/ground.service';
import { Ground } from '../../../Ground';
import * as io from "socket.io-client";
@Component({
moduleId: module.id,
selector: 'ground',
templateUrl: 'ground.component.1.html',
styleUrls: ['ground.component.css']
})
export class GroundComponent{
ground: Ground[];
countttt : Number =0;
constructor(private groundService:GroundService,private ngZone:NgZone){
const socket = io.connect('http://localhost:30003');
this.groundService.getGround()
.subscribe(ground => {
console.log(ground);
this.ground = ground;
});
socket.on("on:chat message", (data) => {
console.log("aa");
});
}
}
My typing.json
{
"globalDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160725163759",
"jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
"node": "registry:dt/node#6.0.0+20160909174046",
"socket.io-client": "registry:dt/socket.io-client#1.4.4+20160317120654"
}
}
下面是我在上面的TypeScript文件中导入的Socket.io-client.js文件的前几行中的依赖项。因此,当它在TS文件中导入Socket.io客户机时,基本上无法在错误中找到文件
/**
* Module dependencies.
*/
var parser = require('socket.io-parser');
var Emitter = require('component-emitter');
var toArray = require('to-array');
var on = require('./on');
var bind = require('component-bind');
var debug = require('debug')('socket.io-client:socket');
var hasBin = require('has-binary');
下面是我正在导入的Socket.io客户端文件夹中的节点模块文件夹
下面是system.config.js
System.config({
map: {
"socket.io-client": "node_modules/socket.io-client/lib/socket.js",
},
packages: {
"socket.io-client": {"defaultExtension": "js"},
}
)};
我传递的URL不正确。在socket.io-client的System.config中–Kshitij Mehta我传递的URL不正确。在socket.io-client的System.config中–Kshitij Mehta我建议您在应用程序中提供更多代码示例,以尝试导入这些代码libraries@Isigiel我补充了一些细节。现在请看一看。谢谢@KshitijMehta,你解决问题了吗?是的。我传递的URL不正确。在socket.io-client的System.config中@PraI建议为我们提供更多的示例,说明您的应用程序中尝试导入这些代码的代码libraries@Isigiel我补充了一些细节。现在请看一看。谢谢@KshitijMehta,你解决问题了吗?是的。我传递的URL不正确。在socket.io-client的System.config中@普拉