Angular & SignalR: $.connection is undefined

Viewed 764

I'm trying to get SignalR to work with an Angular (the 2/4 branch) component & Typescript. So far it appears that jQuery works fine, but $.connection == undefined.

I have installed the node modules and their typings for jQuery & SignalR.

npm install --save jquery
npm install --save signalr
npm install --save @types/jquery
npm install --save @types/signalr

I added the scripts to the .angular-cli.json file

"scripts": ["../node_modules/jquery/dist/jquery.min.js", "../node_modules/signalr/jquery.signalR.min.js"]

I then imported them into my component

import * as $ from 'jquery';
import 'signalr';

I tried doing things with $.connection, but my component wouldn't load since $.connection is undefined. This is my first time working with Angular, so I'm probably missing something obvious here. Like I said, jQuery is working fine but it looks like the SignalR js isn't doing anything.

EDIT: So after looking around more, it does seem like the signalR .js is running; if I type "$.connection" into the console at runtime I get "function(url, qs, logging)" which is what it should be. However in my Angular component if I do "console.log($.connection)" I still get undefined.

EDIT: Fixed the problem by just reducing my import statements to this:

import 'jquery';
import 'signalr';
0 Answers
Related