在浏览器中让Javascript库(与其相关的类型记录类型)在角2中工作时,angular2-polyadds.js中似乎出现了错误。
这是一个奇怪的问题:当库中只有一行代码时,我似乎能够编译和运行,但当我输入第2行时,它就生成了,但没有运行?!
图书馆是AutobahnJS。它是一个单一的.js文件,完全相同的库设计为在浏览器和节点中工作。它作为一个普通的(非angular2) javascript库在浏览器和Node中都工作得很好。我让它在Node中使用类型记录和它的相关类型(在绝对键入的github页面有一个示例测试 )
我已经遵循了基本的角2快速启动的打字稿,并使它没有任何问题。
这是实际工作的代码和输出。注意,testAutobahn()中的最后一行被注释掉:
import {Component} from 'angular2/core';
import autobahn = require('autobahn');
@Component({
selector: 'my-app',
template: `
<h1>Project: {{_projectName}}</h1>
`
})
export class AppComponent {
constructor() {}
private _projectName : string = "EXAMPLE7";
testAutobahn() {
var options: autobahn.IConnectionOptions =
{ url: 'wss://demo.crossbar.io/ws', realm: 'realm1' };
//var connection = new autobahn.Connection(options); // <- THIS line commented out, app runs fine
}
}

下面是不起作用的代码和输出。注意,testAutobahn()中的最后一行保留在:
import {Component} from 'angular2/core';
import autobahn = require('autobahn');
@Component({
selector: 'my-app',
template: `
<h1>Project: {{_projectName}}</h1>
`
})
export class AppComponent {
constructor() {}
private _projectName : string = "EXAMPLE7";
testAutobahn() {
var options: autobahn.IConnectionOptions =
{ url: 'wss://demo.crossbar.io/ws', realm: 'realm1' };
var connection = new autobahn.Connection(options); // <- THIS line left in, app not run!
}
}

唯一的区别是该行的注释/取消注释。这个错误似乎来自angular2-polyadds.js和system.src.js。
我用“tsd”来安装所有的打字机。它们看起来都是正确的,我的编辑原子在高速公路上有智能感知。*类型很好。
可能出现的问题?
“后续变量声明必须具有相同的类型。变量'$‘必须是'cssSelectorHelper’类型,但是这里有‘JQueryStatic’类型。”
-> I have resolved this error by simply commenting out the line /* declare var $: JQueryStatic; */ in the jquery.d.ts file (I'm not using JQuery anyway) 使用类型转录v1.7.5,角2 Beta 0与package.json,tsconfig.json和boot.ts文件,根据角2快速启动的类型记录。我的最终目标是让Angular2服务与AutobahnJS协同工作(但目前还只是初级阶段)。
任何帮助都将不胜感激.
发布于 2016-01-20 14:17:47
现在,我终于开始工作了,并且在AutobahnJS和Range2Service方面取得了一些进展。你可以参考我的柱塞:
[plunker](https://plnkr.co/edit/Dgipr76Rbhgh31PH4pmM)不过我还是被困住了。问题是我不能简单地“调用”一个函数(然后这个函数将继续执行Autobahn session.call(.)方法)返回一个值。例如,我想做一些简单的事情,比如:
var x = myMessageService.DoFunct1( someParameter );https://stackoverflow.com/questions/34780498
复制相似问题