1572421906
WebSocket is a web communication protocol that allows two-way communication between a client and a server. What makes that technology appealing is that unlike regular TCP sockets, WebSockets use the same port as the HTTP protocol, which is port 80.
This means that when using WebSockets you don’t have to worry about firewalls blocking that port and preventing your data to flow between client and server. The technology has been around for a while, long enough to enjoy excellent support across all browsers according to caniuse.com:
How to use WebSockets with RxJs?
This is actually almost too easy. You just have to import the webSocket function from RxJs, call it with the URL of your WebSocket, and… done!
import {webSocket, WebSocketSubject} from 'rxjs/webSocket';
myWebSocket: WebSocketSubject = webSocket('ws://localhost:8000');
You now have an RxJs subject (more info about subjects with this tutorial) that you can subscribe to in order to receive some data:
myWebSocket.asObservable().subscribe(dataFromServer => //...);
And if you want to send data to the server, simply use the next method of your subject:
myWebSocket.next({message: 'some message'});
Also note that when you subscribe to a WebSocket subject, you can register callbacks to be notified when an error happens or when the connection is closed, just like with a regular observable:
myWebSocket.subscribe(
msg => console.log('message received: ' + msg),
// Called whenever there is a message from the server
err => console.log(err),
// Called if WebSocket API signals some kind of error
() => console.log('complete')
// Called when connection is closed (for whatever reason)
);
Thank you for reading !
If you enjoyed this post, please share it. Your help is always appreciated.
#angular #angular8 #typescript #rxjs #websocket
1626834660
In this video, we will see how to improve our code using the #rxs map operator and #angular #async pipe.
The components should be clean and minimal and should not have code that manipulates the data. Responsible for data manipulation is a service.
The goal is to prepare our data and return an #observable pipe so that we can use an #async pipe in the template.
code: https://github.com/profanis/codeShotsWithProfanis/tree/13/rxjsMapAndAsyncPipe
#angular #rxjs #observable #map #async
#angular rxjs #angular #angular tutorial #what is angular
1598940617
Angular is a TypeScript based framework that works in synchronization with HTML, CSS, and JavaScript. To work with angular, domain knowledge of these 3 is required.
In this article, you will get to know about the Angular Environment setup process. After reading this article, you will be able to install, setup, create, and launch your own application in Angular. So let’s start!!!
For Installing Angular on your Machine, there are 2 prerequisites:
First you need to have Node.js installed as Angular require current, active LTS or maintenance LTS version of Node.js
Download and Install Node.js version suitable for your machine’s operating system.
Angular, Angular CLI and Angular applications are dependent on npm packages. By installing Node.js, you have automatically installed the npm Package manager which will be the base for installing angular in your system. To check the presence of npm client and Angular version check of npm client, run this command:
· After executing the command, Angular CLI will get installed within some time. You can check it using the following command
Now as your Angular CLI is installed, you need to create a workspace to work upon your application. Methods for it are:
To create a workspace:
#angular tutorials #angular cli install #angular environment setup #angular version check #download angular #install angular #install angular cli
1572421906
WebSocket is a web communication protocol that allows two-way communication between a client and a server. What makes that technology appealing is that unlike regular TCP sockets, WebSockets use the same port as the HTTP protocol, which is port 80.
This means that when using WebSockets you don’t have to worry about firewalls blocking that port and preventing your data to flow between client and server. The technology has been around for a while, long enough to enjoy excellent support across all browsers according to caniuse.com:
How to use WebSockets with RxJs?
This is actually almost too easy. You just have to import the webSocket function from RxJs, call it with the URL of your WebSocket, and… done!
import {webSocket, WebSocketSubject} from 'rxjs/webSocket';
myWebSocket: WebSocketSubject = webSocket('ws://localhost:8000');
You now have an RxJs subject (more info about subjects with this tutorial) that you can subscribe to in order to receive some data:
myWebSocket.asObservable().subscribe(dataFromServer => //...);
And if you want to send data to the server, simply use the next method of your subject:
myWebSocket.next({message: 'some message'});
Also note that when you subscribe to a WebSocket subject, you can register callbacks to be notified when an error happens or when the connection is closed, just like with a regular observable:
myWebSocket.subscribe(
msg => console.log('message received: ' + msg),
// Called whenever there is a message from the server
err => console.log(err),
// Called if WebSocket API signals some kind of error
() => console.log('complete')
// Called when connection is closed (for whatever reason)
);
Thank you for reading !
If you enjoyed this post, please share it. Your help is always appreciated.
#angular #angular8 #typescript #rxjs #websocket
1636488000
Tutorial sobre el uso del operador switchMap en #RxJS (ReactiveX) en #Angular. Dura más de lo habitual debido a que lo explicamos con dos ejemplos, uno muy básico y uno de los típicamente llamados "Ejemplo de la Vida Real" (Real life example). Para ver los puntos más importantes, les dejamos los siguientes minutos:
1624138795
Learn How to use Angular Material Autocomplete Suggestions Search Input. I covered multiple use cases.
Please watch this video. I hope this video would be helpful for you to understand it and use it in your projects
Please subscribe: https://www.youtube.com/channel/UCL5nKCmpReJZZMe9_bYR89w
#angular #angular-material #angular-js #autocomplete #angular-material-autocomplete #angular-tutorial