这是一个奇怪的问题:我似乎能够在库中只有一行代码的情况下构建和运行,但是当我进入第二行时,它会构建,但不会运行?!?.
该库是AutobahnJS.它是一个.js文件,完全相同的库设计用于浏览器和节点.
它在浏览器和节点中都可以作为普通(非angular2)javascript库完美运行.
我使用Typescript在Node中工作,它是相关的类型(在绝对类型的github页面上有一个example test)
我已经遵循了基本的Angular 2 Quickstart for Typescript并且没有遇到任何问题.
这是代码和输出工作.注意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',realm: 'realm1' }; var connection = new autobahn.Connection(options); // <- THIS line left in,app not run! } }
唯一的区别是该行的评论/取消注释.
错误似乎来自angular2-polyfills.js和system.src.js
我用’tsd’来安装所有的打字机.它们看起来都是正确的,我的编辑器Atom在高速公路上有智能感.*类型就好了.
可能的问题?:
>使用AutobahnJS v0.9.9,但打字似乎适用于v0.9.6
-> I can't see this being a real problem
>构建时,Typescript会发出Javascript代码,但确实会出错:
“Subsequent variable declarations must have the same type. Variable
‘$’ must be of type ‘cssSelectorHelper’,but here has type
‘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)
使用Typescript v1.7.5,Angular 2 Beta 0和package.json,tsconfig.json和boot.ts文件,按照Angular 2 Quickstart for Typescript.
我的最终目标是让Angular2服务与AutobahnJS合作(但目前只是在婴儿的步骤).
任何帮助将不胜感激….