Websocket 404使用Angular2、Angular2网袋和打字
在我的浏览器上,我看到: 获取404(未找到)I @system.src.js:4597(匿名函数) (……) 我在index.html上使用这个定义Websocket 404使用Angular2、Angular2网袋和打字,websocket,angular,systemjs,Websocket,Angular,Systemjs,在我的浏览器上,我看到: 获取404(未找到)I @system.src.js:4597(匿名函数) (……) 我在index.html上使用这个定义 ... import {$WebSocket} from "angular2-websocket/angular2-websocket"; @Injectable() export class DeviceService { private logger:Logger; private ws:$WebSocket;
...
import {$WebSocket} from "angular2-websocket/angular2-websocket";
@Injectable()
export class DeviceService {
private logger:Logger;
private ws:$WebSocket;
constructor(
private _logger: Logger
) {
this.logger=_logger;
this.ws = new $WebSocket("ws://nodered-iot.net/ws/devices");
}
private _devices:Device[] = [];
getDevices() {
this.ws.send("Hello");
...
System.config({
transpiler:'typescript',
typescriptOptions:{emitDecoratorMetadata:true},
包:{'app':{defaultExtension:'ts'},
地图:{
'angular2 websocket':'node_模块/angular2 websocket'
}
});
System.import('app/main')
.then(null,console.error.bind(console));
******编辑*******
我成功地找到了修复程序,因为它:
System.config({
transpiler:'typescript',
typescriptOptions:{emitDecoratorMetadata:true},
套餐:{
'app':{defaultExtension:'ts'},
'js':{defaultExtension:'ts'},
地图:{
“angular2 websocket”:“js”
}
});
System.import('app/main')
.then(null,console.error.bind(console));
我必须将文件从node_模块复制到一个新的js文件夹中。这不是很好,但如果这些文件不在nodeJs的“public”文件夹中,我不知道如何在客户端使用它://我认为这是一个SystemJS配置。你可以试试这个:
<!-- 2. Configure SystemJS -->
<script>
System.config({
transpiler: 'typescript',
typescriptOptions: { emitDecoratorMetadata: true },
packages: {'app': {defaultExtension: 'ts'}},
map: {
'angular2-websocket': 'node_modules/angular2-websocket'
}
});
System.import('app/main')
.then(null, console.error.bind(console));
</script>
System.config({
地图:{
'angular2 websocket':'node_模块/angular2 websocket'
},
套餐:{
(...)
}
});
另一种解决方案是更改节点的根,因为它指向“public”文件夹:
<script>
System.config({
map: {
'angular2-websocket': 'node_modules/angular2-websocket'
},
packages: {
(...)
}
});
</script>
然后我们可以在index.html上声明:
// Serve up the welcome page
httpStatic: path.join(__dirname,"/"),
您是如何包含模块并引用它的?您使用的是SystemJS吗?是的,我使用的是SystemJS。如果我将其添加到index.html中,则会出现以下错误:未捕获类型错误:意外的匿名System.register Call这不起作用。我还需要在“包”上添加什么?我会尽快回来做新的测试。我没有太多的空闲时间做我的POC,混合了很多东西是相当复杂的^_^
<script src="/node_modules/angular2-websocket/angular2-websocket.js"></script>