Primus and angular 2
See original GitHub issueVersion: 4.0.4
Environment:
- Operating system:All
- Browser:All
- Node.js:4
Expected result: Having the possibility to use Primus with typescript for front purpose
Actual result:
IDE and compiler keep telling Primus is not defined
.
If I use the .d.ts
it’s not working because the definition is for the server part when I need the client definition.
Steps to reproduce:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app',
providers: [],
directives: [],
styleUrls: [],
template: ''
})
export class AppComponent implements OnInit {
ngOnInit() {
this.initWebsockets();
}
private initWebsockets() {
//
// Tell primus to create a new connect to the current domain/port/protocol
//
const primus = new Primus('http://localhost:3000?token=....');
//
// Listen for incoming data and log it in our textarea.
//
primus.on('data', function received(data) {
switch (data.action) {
case 'create':
console.log('create');
break;
case 'update':
console.log('update');
break;
case 'destroy':
console.log('destroy');
break;
case 'notification':
console.log('notification');
break;
}
console.log(data);
});
//
// Listen for submits of the form so we can send the message to the server.
//
primus.write({action:'join', room:'notification'});
}
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
angular-primus - npm
Primus provider for Angular. This plugin works with other Primus plugins like primus-emitter and primus-resource.
Read more >Ngrx and Angular 2 Tutorial: Building a Reactive Application
In this article, through building a reactive Angular 2 application using Ngrx, you will learn what the pattern is, where the pattern can...
Read more >Angular 2 · Feathersjs
Using TypeScript. If you're using TypeScript to develop with Angular 2, Feathers and its related modules should be loaded into your app through...
Read more >Modeling the head of PRIMUS linear accelerator for electron ...
For the beam profiles comparison, the differences ranged from 2% (2 mm) to ... spectra and angular distributions of photons and electrons.
Read more >PRIMUS Global Services, Inc: Full-Stack .NET Developer – Angular ...
NET Developer – Angular, Azure, Microservices - 100% REMOTE 18237 ... C# and experience with Microsoft Visual Studio, Angular 2, HTML5, JSON and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Get latest version of primus
In config.js where System.config is defined, put this:
and in map object put this:
in angular:
@justinweathersby 3 years after my last comment and solution… uhhh… lot of things have changed in Angular world since then. Luckily for you, i am still using Angular + Primus and i have new method how to implement and use it in Angular 7. First of all, save client library in some folder of your Angular 7 project. (you can extract it from backend side or start the backend server and get it by url, check the docs) Then you can use it like import * as Primus from ‘place_to_the_file/primus.js’; Somewhere in your code do this for example: this.primusInstance = Primus.connect(url); // Url is url to your site like ‘ws://examplesite.abc’; use primusInstance for data handling, receiving, sending data…