1560863199
Originally published by Gideon Onwuka at https://pusher.com
In this tutorial, I will walk you through how you can add a realtime subscription count down functionality to your Angular application.
In the app, we’ll have a page that displays the subscribers status, that is, the number of slots left. Then we will have another page for users to register themselves. Once the number of users that are registered is equal to the target of users that we want, then we close the registration in realtime.
At times, we need to present things to our users in a realtime manner so they know beforehand when things tend to happen. Consider that we are building an app where there are limited resources and we need maybe a limited amount of user. In such cases, It’s a better idea to let the user know what is happening in realtime. That is showing the user the slots that are remaining.
Here is a preview of what we are going to build:
You are required to have a basic knowledge of the following technologies to be able to follow along with this tutorial comfortably:
Let’s get your system ready. First check that you have Node installed by typing the below command in a terminal on your system:
$ node --version
The above command should print out the version of Node you have installed. If otherwise, you don’t have Node, visit the Node.js’s website and install the latest version of Node to your system.
Next, let’s install the Angular CLI. Angular provides a CLI that makes scaffolding of new Angular project and also working with Angular easier.
Install the Angular CLI globally to your system if you don’t have it installed already by executing the below command to a terminal on your system.
$ npm install -g @angular/cli
If that was successful, you should now have the Angular command available globally on your system as ng
.
Now use the Angular CLI command to create a new Angular project:
$ ng new subscription-count-down
Choose yes for the prompt that asks if you Would like to add Angular routing and choose CSS for the stylesheet format. Then give it some minute to finalize the process.
Finally, cd into the newly created project and start up the app:
$ cd subscription-count-down
$ ng serve --open
The app should now be available at http://localhost:4200 displaying a default Angular page like below:
The src/app/app.component.ts
file is the default component file that renders the page above.
We’ll be using Channels’s pub/sub messaging feature to add realtime functionality to our app. The next thing we’ll do is to get our Channels API keys.
Head over to Channels website and create a free account if you don’t have one already. Once you are logged into your Dashboard, create a new app and get the API keys of the app.
The keys are in this format:
appId=<appId>
key=<key>
secret=<secret>
cluster=<cluster>
Take note of these keys because we’ll be making use of them soon.
Next, add the API key to the environment file so we can reference it from other files when we need it by replacing the content with below:
// src/environments/environment.ts
export const environment = {
production: false,
apiUrl: 'http://localhost:3000',
PUSHER_API_KEY: '<PUSHER_API_KEY>',
PUSHER_API_CLUSTER: '<PUSHER_APP_CLUSTER>'
};
Make sure to replace <PUSHER_API_KEY>
and <PUSHER_APP_CLUSTER>
placeholders with your correct API details.
In the object file above, the apiUrl
property is the URL where our Node server will be running on which we’ll be creating later on.
Finally, add the pusher client SDK to the Angular app:
$ npm install pusher-js
You should run the command while in the root folder of the project from a command line.## Creating the Node server
We need a server to be able to trigger events to Channels and also for creating and storing users. For the sake of brevity, we’ll use SQLite for our database. And we’ll be using Node for our server.
To set up a Node server, open up a new terminal, then run the following command in your terminal:
# Create a new folder
$ mkdir subscription-count-down-server
# Navigate to the folder
$ cd subscription-count-down-server
# Create the Node entry file
$ touch app.js
# Create a package.js file
$ touch package.json
# Create the database file
$ touch app.db
# Create the environment file for holding sensitive data
$ touch .env
These are the basic files we will need for the Node server.
Now add to the package.json
file the necessary dependencies for the app:
{
"name": "count-down-server",
"version": "1.0.0",
"description": "Count Down Server",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"serve": "node app.js"
},
"keywords": [
"Node",
"Count-Down",
"Pusher"
],
"author": "Onwuka Gideon",
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.3",
"cors": "^2.8.5",
"dotenv": "^6.2.0",
"express": "^4.16.4",
"pusher": "^2.2.0",
"sqlite3": "^4.0.6"
}
}
Next, add your Channels key to the .env
file:
PUSHER_APP_ID=<appId>
PUSHER_APP_KEY=<key>
PUSHER_APP_SECRET=<secret>
PUSHER_APP_CLUSTER=<cluster>
Make sure to replace <appId>
, <key>
, <secret>
, and <cluster>
placeholders with your correct API details.
Now import the dependencies we added earlier to the app.js
file:
// app.js
require('dotenv').config()
const express = require('express')
const cors = require('cors')
const bodyParser = require('body-parser')
const sqlite3 = require('sqlite3').verbose();
const Pusher = require('pusher');
Then, set up express, which is a Node.js web application framework for building web apps.
// app.js
// [...]
const app = express()
const port = 3000
app.use(cors())
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/', (req, res) => res.status(200).send({msg: "Count down server!"}))
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
// [...]
In the above code, we created a new route - /
- which will render a JSON content once visited. We are only using it to test if express is working.
Now install the dependencies and start up the app:
# Instal dependencies
$ npm install
# Start up the app
$ npm run serve
If everything went well, the app should be accessible from http://localhost:3000/. If you visit the URL, you should get an output as below which shows that it works!
{
"msg": "Count down server!"
}
Next, initialize the database:
// app.js
// [...]
const db = new sqlite3.Database('./app.db', sqlite3.OPEN_READWRITE);
db.run("CREATE TABLE IF NOT EXISTS subscriptions (email VARCHAR(90), name VARCHAR(90))")
// [...]
The first line above opens a new SQLite connection. While the second line checks if the subscriptions table exists, if it does not exists, it will create it.
Next, initialize Pusher server SDK:
// app.js
// [...]
const pusher = new Pusher({
appId: process.env.PUSHER_APP_ID,
key: process.env.PUSHER_APP_KEY,
secret: process.env.PUSHER_APP_SECRET,
cluster: process.env.PUSHER_APP_CLUSTER,
encrypted: true
});
// [...]
Now create a new route that we can use to get the total number of users that have subscribed and the number of targets we want. The target is the maximum number of users that we want to be able to subscribe:
// app.js
// [...]
app.get('/userCount', (req, res) => {
db.each(`SELECT count(*) AS userCount FROM subscriptions`, (err, row) => {
res.status(201).send({userCount: row.userCount, targetCount: 5})
});
})
// [...]
Here, we hard-coded the targetCount
to five. If the total number of registered user reaches five, no other user should be able to register again.
Next, create a new endpoint named addUser
for adding new users:
// app.js
// [...]
app.post('/addUser', (req, res) => {
const email = req.body.email;
const name = req.body.name;
db.run(`INSERT INTO subscriptions (name, email) values ('${name}', '${email}')`)
db.serialize(function() {
db.each(`SELECT count(*) AS userCount FROM subscriptions`, (err, row) => {
res.status(201).send({userCount: row.userCount})
});
});
})
// [...]
Finally, create a new endpoint named /pusher/trigger
for triggering events to Channels.
// app.js
// [...]
app.post('/pusher/trigger', (req, res) => {
const channel_name = req.body.channel_name;
const event_name = req.body.event_name;
const data = req.body.data;
pusher.trigger(channel_name, event_name, data);
res.status(200).send(data)
})
// [...]
To trigger events to Channels, we call the trigger method from the Pusher SDK passing along the name of the channel where we want to trigger the event to, the name of the event, and some data to pass along with the event.
Restart the server so the new changes will be picked up.
Before we start building the app components, let’s create the service for our app. We’ll create two services - count-down service and pusher service. The count-down service will contain services for the entire component while the pusher service will contain services that are related to Channels, say we want to trigger event or listen to an event.
In Angular, services are great ways of sharing information among classes that don’t know each other.
Now, create the count-down service using the Angular CLI command:
# Make sure you are in the root folder of the project
$ ng generate service count-down
You should now see a new file that is created named src/app/count-down.service.ts
.
Inside the file, replace its content with the below code:
// src/app/count-down.service.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { environment } from '../environments/environment';
interface userCount {
userCount: number,
targetCount: number
}
export interface userData {
name: String;
email: String;
}
@Injectable({
providedIn: 'root'
})
export class CountDownService {
constructor(private http: HttpClient) { }
getUserCount (): Observable<userCount> {
return this.http.get<userCount>(`${environment.apiUrl}/userCount`)
}
addNewUser (userData: userData): Observable<userData> {
return this.http.post<userData>(`${environment.apiUrl}/addUser`, userData)
}
}
In the preceding code:
Next, create the Pusher service
$ ng generate service pusher
Now update the content of the service file:
// src/app/pusher.service.ts
import { Injectable } from '@angular/core';
import Pusher from 'pusher-js';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { environment } from '../environments/environment';
@Injectable({
providedIn: 'root'
})
export class PusherService {
pusher: any
constructor(private http: HttpClient) {
this.pusher = new Pusher(environment.PUSHER_API_KEY, {
cluster: environment.PUSHER_API_CLUSTER,
forceTLS: true
});
}
subScribeToChannel(channelName: String, events: String[], cb: Function) {
var channel = this.pusher.subscribe(channelName);
events.forEach( event => {
channel.bind(event, function(data) {
cb(data)
});
})
}
triggerEvent(channelName: String, event: String, data: Object): Observable<Object> {
return this.http.post(`${environment.apiUrl}/pusher/trigger`, {
channel_name: channelName,
event_name: event,
data: data
})
}
}
In the preceding code:
Now let’s build the client-facing part of the app which we are doing with Angular. We’ll divide the app into two components:
Before you can use the HttpClient, we need to import the Angular HttpClientModule. Import the HttpClientModule to the app.module.ts
file:
// src/app/app.module.ts
[...]
import { HttpClientModule } from '@angular/common/http';
[...]
imports: [
[...]
HttpClientModule,
[...]
],
[...]
Create the CountDown component using the Angular CLI command:
$ ng generate component count-down
The above command will create a new folder, src/app/count-down/
, and generates the four files for the CountDownComponent
.
The count-down.component.ts
is the main component class, which includes the other three files to itself. This is the file that will contain the logic for the component.
All our markup definitions go inside the count-down.component.html
file. CSS styles for the component will reside in the count-down.component.css
file. If we need to write a test for the component, we can do that in the count-down.component.spec.ts
file.
Update the route to render this component:
// src/app/app-routing.module.ts
// [...]
import { CountDownComponent } from './count-down/count-down.component';
const routes: Routes = [
{ path: '', component: CountDownComponent }
];
// [...]
Next, remove the default rendered page and replace it with the below mark-up:
<!-- src/app/app.component.html -->
<div class="container">
<div class="content">
<router-outlet></router-outlet>
</div>
</div>
If you now reload the page, you see it renders the html file for the CountDown component:
Next, update the markup for the CountDown component:
<!-- src/app/count-down/count-down.component.html -->
<div>
<div *ngIf="!countDown"> Registration closed! </div>
<nav *ngIf="countDown">
<a routerLink="/register">Register</a>
</nav>
<h1>Subscription count down:</h1>
<div class="count-down"> {{ countDown }} </div>
</div>
Now add some styling to the app:
/* src/style.css */
h1 {
color: #369;
font-family: Arial, Helvetica, sans-serif;
font-size: 200%;
}
h2, h3 {
color: #369;
font-family: Arial, Helvetica, sans-serif;
font-weight: lighter;
}
body {
overflow: hidden;
}
body, input[type="text"], button {
color: #888;
font-family: Cambria, Georgia;
}
/* everywhere else */
* {
font-family: Arial, Helvetica, sans-serif;
}
.container {
display: grid;
height: 100vh;
width: 100vw;
}
.content {
align-self: center;
justify-self: center;
}
.count-down {
text-align: center;
font-size: 300%;
}
.from-input {
display: block;
width: 300px;
margin: 8px;
padding: 15px;
font-size: 100%;
}
.from-submit {
background: #369;
color: white;
font-family: Arial, Helvetica, sans-serif;
font-size: 140%;
border-radius: 3px;
width: 100%;
padding: 10px;
}
.success-message {
background: green;
color: antiquewhite;
padding: 10px;
border-radius: 3px;
margin: 4px;
}
Reload the page to see how it looks now.
We have been able to render the CountDown component, but it does not show real data yet. And also it is showing “registration is closed!”. It should show that when the users registered is equal to the target users and otherwise show a registration form.
Now, let’s work on this component.
Import the two services we created earlier to the component file:
// src/app/count-down/count-down.component.ts
// [...]
import { CountDownService } from '../count-down.service';
import { PusherService } from '../pusher.service';
// [...]
Notice that we are rendering the {{ countDown }}
variable to the markup file, which does not have any effect because we have not defined the variable. This variable will hold the number of slots remaining.
Define the variable:
// src/app/count-down/count-down.component.ts
// [...]
export class CountDownComponent implements OnInit {
countDown: number;
// [...]
Next, inject the services we imported to the component class so we can access them easily:
// src/app/count-down.component.ts
// [....]
constructor(
private countDownService: CountDownService,
private pusherService: PusherService
) { }
// [....]
Now we want to get the countDown value from the Node server when the page loads and also listen to new events when a new user subscribes.
// src/app/count-down.component.ts
// [....]
ngOnInit() {
this.countDownService.getUserCount()
.subscribe(data => {
this.countDown = data.targetCount - data.userCount
});
this.pusherService.subScribeToChannel('count-down', ['newSub'], (data) => {
// console.log(data)
this.countDown -= 1;
});
}
// [....]
Now when the component is mounted, we call the getUserCount()
function from the countDownService service to get the targetCount and userCount, which we then use to calculate the number of the slots that are remaining.
Then, we call the pusherService.subScribeToChannel()
function to the count-down and start listening for a newSub event. Once there is a newSub event, we reduce the countDown
value by one. And all this happens in realtime. Note that the channel name (‘count-down’) and event name (‘newSub’) can be anything you like. You only need to make sure that you trigger the same value on the Node server if you change it.
If you reload the page, you should see now that it shows the remaining slots and also a link where a user can register form.
We also need another component that renders the form for a user to subscribe.
Create the Register component using the Angular CLI command:
$ ng generate component register
Add a route that renders the Register component:
// src/app/app-routing.module.ts
[...]
import { RegisterComponent } from './register/register.component';
[...]
const routes: Routes = [
{ path: 'register', component: RegisterComponent },
{ path: '', component: CountDownComponent}
];
[...]
Now, if we visit http://localhost:4200/register, it should show the register page.
Next, import the two services we created earlier to the component file:
// src/app/register/register.component.ts
// [...]
import { CountDownService, userData } from '../count-down.service';
import { PusherService } from '../pusher.service';
// [...]
Define the input form detail for two-way binding:
// [...]
export class RegisterComponent implements OnInit {
userData: userData = {
name: '',
email: ''
};
userAdded: Boolean = false
// [...]
The userData
is the input we are expecting from the user as they fill the registration form. We’ll use userAdded
Boolean to toggle between when to show the user a success message as the submit the form.
Next, inject the service we imported to the class:
// src/app/register/register.component.ts
// [....]
constructor(
private countDownService: CountDownService,
private pusherService: PusherService
) { }
// [....]
Next, add a function that will be called when a user clicks to submit the form:
// [...]
ngOnInit() {}
addUser(): void {
this.countDownService.addNewUser(this.userData)
.subscribe( data => {
this.userAdded = true
this.userData = {name:'', email:''}
})
this.pusherService.triggerEvent('count-down', 'newSub', this.userData)
.subscribe( data => {
console.log(data)
})
}
// [...]
In the function we created above, we call the addNewUser
function from the countDownService to register the user. Then finally, we trigger an event to Channels so it notifies all connected user that a new user has just registered so that the count down number is updated.
Next, update the HTML mark up for the form:
<!-- src/app/register/register.component.html -->
<div>
<nav>
<a routerLink="/">Got to count-down</a>
</nav>
<div>
<div class="success-message" *ngIf="userAdded"> User Created Successfully! </div>
<form>
<input
type="text"
class="from-input"
placeholder="Email"
[(ngModel)]="userData.email"
name="email"
/>
<input
type="text"
class="from-input"
placeholder="Name"
[(ngModel)]="userData.name"
name="name"
/>
<button class="from-submit" (click)="addUser()"> Submit </button>
</form>
</div>
</div>
Finally, add the FormsModule, which is required when working with forms:
// src/app/app.module.ts
[...]
import { FormsModule } from '@angular/forms';
[...]
imports: [
[...]
FormsModule,
[...]
],
[...]
And that is it! Let’s test what we have built:
In this tutorial, we have learned how to add realtime functionality to our Angular apps by building a subscription count down app. There are other use-cases where this same approach can be applied to. Feel free to them explore with the knowledge that you have gained.
You can get the complete code of the app on GitHub.
This article was originally published at https://pusher.com/tutorials/live-countdown-angular
#angular #node-js #javascript
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
1593184320
What is Angular? What it does? How we implement it in a project? So, here are some basics of angular to let you learn more about angular.
Angular is a Typescript-based open-source front-end web application platform. The Angular Team at Google and a community of individuals and corporations lead it. Angular lets you extend HTML’s syntax to express your apps’ components clearly. The angular resolves challenges while developing a single page and cross-platform applications. So, here the meaning of the single-page applications in angular is that the index.html file serves the app. And, the index.html file links other files to it.
We build angular applications with basic concepts which are NgModules. It provides a compilation context for components. At the beginning of an angular project, the command-line interface provides a built-in component which is the root component. But, NgModule can add a number of additional components. These can be created through a template or loaded from a router. This is what a compilation context about.
Components are key features in Angular. It controls a patch of the screen called a view. A couple of components that we create on our own helps to build a whole application. In the end, the root component or the app component holds our entire application. The component has its business logic that it does to support the view inside the class. The class interacts with the view through an API of properties and methods. All the components added by us in the application are not linked to the index.html. But, they link to the app.component.html through the selectors. A component can be a component and not only a typescript class by adding a decorator @Component. Then, for further access, a class can import it. The decorator contains some metadata like selector, template, and style. Here’s an example of how a component decorator looks like:
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss']
})
Modules are the package of functionalities of our app. It gives Angular the information about which features does my app has and what feature it uses. It is an empty Typescript class, but we transform it by adding a decorator @NgModule. So, we have four properties that we set up on the object pass to @NgModule. The four properties are declarations, imports, providers, and bootstrap. All the built-in new components add up to the declarations array in @NgModule.
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
HttpClientModule,
AppRoutingModule,
FormsModule
],
bootstrap: [AppComponent]
})
Data Binding is the communication between the Typescript code of the component and the template. So, we have different kinds of data binding given below:
#angular #javascript #tech blogs #user interface (ui) #angular #angular fundamentals #angular tutorial #basics of angular
1593782362
Do you Increase your Website Engagment?
I analysed, ranked and reviewed best live video streaming chat APIs and SDKs for your web & mobile app based on client reviews and ratings. portfolio, usecases, cost, secure streaming, live chat features, cost, support, etc.
Turn your viewers into participatients with Live Streaming Chat Solutions. There are lot of Real-time chat apis & SDks Providers have in online market now. You can easily integrte and customize real time chat solutions into your new or existing live video streaming web and iOS & android applications. Below have mentioned best real time chat api & SDk Proivders.
CONTUS Fly is one of the leading real time messaging software providers in the market for a decade. Their messaging platforms are completely customizable since they provide Chat APIs and SDKs to integrate real time chat feasibility on your live streaming applications irrespective of audience base. Engage your audience like a live concert, stadium like experience through digitally. Create channels for every live streaming event, sports or anything that would create buzz. Enable audience to interact with each other over voice, video chats and real-time text chats with engaging emojis. CONTUS Fly enables users to add emojis and stickers to captivate each audience and create fun.
To make every live streaming and broadcasting videos more engaging and entertaining, Apphitect’s instant messaging comes with exciting Instant messaging chat APIs to add chat into streaming applications. Apphitect is built with multiple real time communication features like video chat, voice chat and real-time chat to your streaming apps. Their solution surprisingly has a wide range of features to communicate, engage and increase subscription benefits.
One of the enterprise-grade real-time chat solutions built to create virtual chat experience for live streaming events and websites for big brands and startups. Irrespective of audience base, category, MirrorFly provides customizable real time chat APIs to add virtual communication mediums on live streaming and broadcasting applications. Their solution comes with absolute moderation tools and open channels to talk and listen with your audience. MirrorFly’s server infrastructure has the potential to handle concurrent messages and users and to achieve maximum sales conversion.
When it comes to building a live streaming chat app software that covers the entire platforms and demand All-in-One package (features, Customization to any extent) with a one-time payment for lifetime performance, then undoubtedly Contus Fly makes the right choice to partner with. The company offers live broadcasting SDK for Android/iOS and chat APIs for customization.
Being a leading real time chat platform provider in the market, Sendbird has its own hallmark of communication features to the world’s most prominent live streaming applications. Their real time chat solution enables broadcasting and streaming platform’ owners to create a physical equivalent digital chat experience for the audience during any live event streaming to interact, collaborate and cheer together within the same streaming screen. By creating open channels and groups, you can enable the audience to interact with each other during any streaming, engage them with polls, stickers, multiple communication channels and more.
Agora, a deep integratable API available in the market to deliver live interactive streaming experience for workplace, enterprises, gaming, retail, telehealth and social live streaming websites. With easy-to-embed SDKs, Agora empowers businesses to add HD and low latency video and voice chat features into any streaming platforms and channels. Their easy-to-embed real time chat features encourage higher levels of user engagement and opportunity to drive more audience.
Their smart and secure chat APIs deliver real-time chat feasibility for live and on-demand video streaming websites. The real time chat features provides users to communicate and engage within the same streaming platform irrespective of interaction medium and audience count. Enablex offers platform-as-a-service communication solutions for real time messaging integration with APIs hosting possibility on public, private and cloud deployment. Their APIs are enriched with multiple communication features and engagement tools like live-polls, stickers and more.
In order to increase user engagement with live and remote audiences, Pubnub offers real time messaging chat functionality with interactive features to drive event-based engagement with mass chat. Their in-app chat feature enhances live programs, event streaming and blogging content with live polling, multiple chats and more. It also enables live streaming websites to build community, channels and super groups during live streaming to bring the entire audience base to one place.
Vonage is a prime provider of communication APIs for major industrial sectors and enterprise workplaces. With its API, businesses such as live streaming applications can integrate in-app messaging features into any streaming platforms on Android, iOS and Web to empower user engagement. Their APIs are powered with scalable infrastructure and provide multiple communication mediums such as in-app voice, video and chat proactively engaging the audience.
Firekast provides a customizable live chat widget with HTML code for streaming players to enable chat within any streaming or on-demand videos. The chat widget gives the ability for brands and content owners to make the audience to interact with each other for better engagement and proactivity during streaming. The Firekast Live chat comes with moderator tools that will allow administrators to delete or ban abusive content and users from the channel or groups. Firekast’s live chat comes with a private chat widget to create public or private chat rooms to make effective collaboration and discussions.
Conclusion
And this is all the real time chat providers in the market to implement chat functionality in any live streaming or broadcasting platforms. More than delivering entertaining live content, creating a massive engagement and buzz for every live event is the smarter way to turn every audience into a protiable subscriber. Picking up the right software provider is more important than just handling the integration process.
#live #live-streaming-solutions #live-streaming-chat-api #live-streaming-chat-sdk #chat-api-for-live-broadcasting
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
1602670740
In my early Angular days, I would subscribe to observables without unsubscribing before the app was destroyed, possibly leading to a build up of memory leaks. For example:
class AppComponent implements OnInit {
myData: MyDataType[];
constructor(private httpClient: HttpClient){ }
ngOnInit() {
this.httpClient
.get('/api/my-data')
.subscribe((data: MyDataType[]) => {
myData = data;
});
}
}
#angular-subscription #angular #typescript #angular-tutorial #rxjs