Angular2 does not work with javascript base library

It seems that the error in angular2 -polyfills.js when getting the Javascript library (with the Typescript types associated with it) works in Angular 2 in the browser.

This is a strange problem: I seem to be able to build and run when there is only 1 line of code in the library, but when I enter the second line, it builds but does not start?!?.

AutobahnJS library . This is a single .js file and an accurate library designed to work both in the browser and in Node. It works fine both in the browser and in Node as a regular (not angular2) javascript library. I work in Node using Typescript and its associated Types (there is an example test example on the Definitively Typed github page)

I followed the core Angular 2 Quickstart for Typescript and did not work without problems.

HERE is the code and output that work. Note that the last line in testAutobahn () is commented out:

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
    }
}

output-working

HERE - code and output that DO NOT work. Note that the last line in testAutobahn () is left in:

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!
    }
}

output-notworking

The only difference is commenting / uncommenting this line. It looks like the error came from angular2 -polyfills.js and system.src.js

I used 'tsd' to install all types. They all look right, and my Atom editor has intellisense on Autobahn. * Type is just fine.

Possible problems?:

  • Using AutobahnJS v0.9.9, but it seems to be for V0.9.6.

    -> I can't see this being a real problem
    
  • Typescript emits Javascript when building, but it gives an error:

" . '$' '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) 

Typescript v1.7.5, Angular 2 Beta 0 package.json, tsconfig.json boot.ts Angular 2 Quickstart Typescript. - Angular2, AutobahnJS ( ).

....

+4
1

, AutobahnJS Angular 2. :

[plunker](https://plnkr.co/edit/Dgipr76Rbhgh31PH4pmM)

. , "" ( Autobahn session.call(...)), . , - , :

var x = myMessageService.DoFunct1( someParameter );
0

Source: https://habr.com/ru/post/1624203/


All Articles