Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Use ngModel for string Interpolation and create a button to empty string and disable button if it empty.

Answer»

Use ngModel for string Interpolation and create a button to empty string and disable button if it empty.
For this we have create a NEW component as we have tried this in new component and name of component is servers. Below is the command to add a new component in angular project

ng G c componentname

And below is the code for string Interpolation and CREATING a button to empty the string
(1)In .TS file we add below code
import { Component, OnInit } from 'angular/core';

Component({
selector: '[app-servers]',
templateUrl: './servers.component.html',
styleUrls: ['./servers.component.css']
})
export class ServersComponent implements OnInit {
serverName = 'TestServer';

constructor() {
}
ngOnInit() {
}
onUpdateServerName(event: Event)
{
this.serverName = (< HTMLInputElement>event.target).value;
}
}


String Interpolation Ts
(2)In HTML file we use below code
input type="text"
class="form-control"
[(ngModel)] = "serverName"

button
class="btn btn-primary"
[disabled]="serverName === ''"
(click)="serverName=''"




String InterpolationHTML

2.

Enable button through code after five seconds of page load in angular node js?

Answer»

Enable button through code after five SECONDS of page LOAD in angular node js?
To enable button after 5 seconds in angular we NEED to do some code change in .HTML and .ts file as give below. Once page is load button will automatically enable in five seconds.
(1)Below code need to add in .ts file

constructor() {
SETTIMEOUT(() => {
this.allowNewServer = true;
}, 2000);

and below is the image for above code


Angular TS File

(2)Below is the code need to apply on .HTML page to apply conditionon button as given below

[disabled]="!allowNewServer"

And below is the image for the same


Angular button

3.

Seven most common differences between Promises and Observables?

Answer»

Seven most common differences between PROMISES and Observables?
Below are the seven most common difference between Promises and Observables in Angular 8:-

(1)Promises:-Promises always be a asynchronous.
(1)Observables:-Obserables are both synchronous and asynchronous.

(2)Promises:-Promises will deal with single asynchronous event at a time.
(2)Observables:-With the observables we can handle sequence of asynchronous events over a period of time.

(3)Promises:-We will get only single value in Promises.
(3)Observables:-And we will get multiple VALUES in observables.

(4)Promises:-We can say promises are not LAZY and will execute soon after the creation of promises.
(4)Observables:-And we can say observables are very lazy and they will not execute till we subscribe them by USING subscribe() method.

(5)Promises:-We cannot cancel the promises.
(5)Observables:-We can cancel the observables by using unsubscribe() mthod. After that, they stop the listener from receiving further values.

(6)Promises:-We cannot do any operation in Promises.
(6)Observables:-And with the helps of observable we can map for foreach, filter, reduce, retry and retrywhen operators.

(7)Promises:-When we say about the error promises push errors to child promises.
(7)Observables:-And when when we say error in observable it will deliver errors to subscribers.