8
    /// <reference path="../typings/signalr/signalr.d.ts" />
/// <reference path="../typings/jquery/jquery.d.ts" />

interface IMyBlackjack {

}

module My {
    export class MyBlackjack implements IMyBlackjack {

        private hub: HubProxy;
        private cnn: HubConnection;

        constructor() {
            $("#formBlackJack").hide();

            this.cnn = $.hubConnection();
            this.hub = this.cnn.createHubProxy("blackjackHub");
            this.cnn.start(() => this.onConnStart);
        }

        private onConnStart(): void {
            $("#formBlackJack").show();
            this.hub.invoke('hello');
        }
    }
}

var myBlackjack: IMyBlackjack = new My.MyBlackjack();

there is a problem in the code:

this.hub.invoke('hello');

this.hub is surprisingly undefined.

And I hope it should be an object. Any thoughts about it ?

1 Answer 1

11

this is not pointing to the instance. Fix use a lambda:

    private onConnStart = () => {
        $("#formBlackJack").show();
        this.hub.invoke('hello');
    }

More: https://www.youtube.com/watch?v=tvocUcbCupA

also

this.cnn.start(() => this.onConnStart);

perhaps you meant to call i.e. () => this.onConnStart()

Sign up to request clarification or add additional context in comments.

2 Comments

Unfortunately, in your case onConnStart callback doesn't work. So there is a problem.
thanks for this. was scratching my head before. makes sense, but it also not consistent. cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.