I have written an angular Programming interview Question and Answers
Q1 How to add two values in angular?
Ans - In angular write a function look like
addfun(){
let a =5; let b=6 ; let c =a+b;
console.log(c);
}
output 11
if you want to input from the user side then how to write
addfun(a,b){
const c =a+b;
console.log(c) } same if you want to subtract, multiply, divide code
Q 2-How do Change the index value in angular?
first, you write the loop in the Html file line;i= index and pass the index value in your function like (change)="ChangeArrayvalue(arr,index);"
ChangeArrayvalue(arr,index){
if(arr.length >0){
arr[i].name='ram';
arr[i].mob='8877899998'
}
}
Q 3-How do you change an array of object values in angular?
Find the array
changeArrayobject(arr:any){
if(arr.length >0){
const changearr=arr.map(item=>item.name='pankaj');
}
}
In the above code change the value of the name object in your array and assign it to Pankaj
Q 4- How to remove duplicate elements from Angular Array?
Different methods are available in angular to remove the duplicate value
var arr = ["ram", "mango", "shyam",
"ram", "mango", "shyam"];
removeDuplicateA(arr) {
return arr.filter((item,
index) => arr.indexOf(item) === index);
}
console.log(removeDuplicatesA(arr));
Output : [ram, mango,shyam]
The second method in Angular using Foreach Methods
var arr = ["ram", "mango", "shyam",
"ram", "mango", "shyam"];
removeDuplicatesFor(arr) {
var uniquearray = [];
arr.forEach(element => {
if (!uniquearray .includes(element)) {
uniquearray .push(element);
}
});
return uniquearray ;
}
console.log(removeDuplicatesFor(arr));
var arr = ["ram", "mango", "shyam",
"ram", "mango", "shyam"];
removeDuplicatesreduce(arrvalue) {
var uniqueArr = arrvalue.reduce(function (acc, curr) {
if (!acc.includes(curr))
acc.push(curr);
return acc;
}, []);
return uniqueArr ;
}
console.log(removeDuplicatesreduce(arr));
Q-5 How to Array sort my desc order in angular?
descorderfun(arr){
return arr.sort((a,b) => b - a);
}
It's very simple to write a program using the sort method.
if you sort specific objects into an array
Q-6
How do you remove a specific CSS class from an element using JavaScript or jQuery?
Q-7 What do the functions addClass and toggleClass do in JavaScript?
changeClass()
{
document.getElementById("class_demo").className = "btn btn-danger btn-lg";
}
Q-8 What are the benefits of learning AngularJS and React JS for web development? How can someone learn both AngularJS and React JS effectively?
Actually, js technology is related to each other only the writing structure is different. If you learn Angualrjs or Reactjs so you need first learn javascript and typescript.
if you work on angular js easy for ionic mobile application development and if you want to learn to react js then easy React Native Mobile Application
9- What is a pipe in angular and why use pipe in angular?
Ans- pipe is used to transform data in angular application. if you want to change the date format then
for example if write in Html {{ dateobj | date}} or you write parametrize object {{dateobj | date,"YYYY|MM|dd"}}
Q 10- How to place at index position 0 the element between index 3 to 6
given array in javascript?
Q 11- What is data binding why use data binding?
Ans - Data binding is used for showing data in a form and communicating with
components. Data binding basically three types of binding
I -One-way from data source to view target. is also known property binding
syntax is {{dataexpression}} or [property]=" expression".
II - One-way from view target to data source is also known as Event binding.
syntax is (target)="statement"
III - Two -way binding
[(target)]="expression".
two way binding are using when the form input and output both condition required .
Q 12- What is the difference between AOT and JIT?
Ans- The difference between AOT and JIT is a matter of timing and tooling. With AOT, the compiler runs once at build time using one set of libraries; with JIT it runs every time for every user at runtime using a different set of libraries.
JIT downloads the compiler and compiles code exactly before Displaying in the browser. AOT has already complied with the code while building your application, so it doesn't have to compile at runtime. Loading in JIT is slower than the AOT because it needs to compile your application at runtime.
Another way
Just-in-Time (JIT) Compiles your application in the browser at runtime. This was the default until Angular 8. Ahead-of-Time (AOT) Compiles your application and libraries at build time.
Q13 -Why is AOT faster than JIT?
AOT compilers can also spend as much time optimizing as they like, whereas JIT compilation is bound by time requirements (to maintain responsiveness) and the resources of the client machine. For this reason, AOT compilers can perform complex optimization that would be too costly during JIT
An example of a pull inventory control system is the just-in-time, or JIT system. The goal is to keep inventory levels to a minimum by only having enough inventory, not more or less, to meet customer demand.
15- What are decorators in Angular?
Decorators are design patterns or functions that define how Angular features work. They are used to make prior modifications to a class, service, or filter. Angular supports four types of decorators, they are:
- Class Decorators: Class decorators, such as @Component and @NgModule
- Property Decorators: Property decorators for properties inside classes, such as @Input and @Output
- Method Decorators: Method decorators for methods inside classes, such as @HostListener
- Parameter Decorators:Parameter decorators for parameters inside class constructors, such as @Inject
nice question
ReplyDeleteWhat are the reasons why some developers hate AngularJS but love React?
ReplyDeleteIs it easy to learn AngularJS if you know ReactJS?
ReplyDeleteCan you send me a picture of what you're doing right now?
ReplyDeleteWhat is the difference between the scope and ng-model directives in AngularJS?
ReplyDelete