Angular JS
Angular JS
All rights reserved. No part of this book can be reproduced or stored in any retrieval system or transmitted in any
form or by any means, electronic, mechanical, photocopying, recording, uploading on server and scanning without
the prior written permission of the Dot Net Tricks Innovation Pvt. Ltd.
The author of this book has tried their best to ensure the accuracy of the information described in this book.
However, the author cannot guarantee the accuracy of the information contained in this book. The author or Dot
Net Tricks Innovation Pvt. Ltd. will not be liable for any damages, incidental or consequential caused directly or
indirectly by this book.
Further, readers should be aware that the websites or reference links listed in this book may have changed or
disappeared between when this book was written and when it is read.
All other trademarks referred to in this book are the property of their respective owners.
Release History
• Initial Release 1.0.0 - 1st Jan 2015
• Second Release 1.0.1 - 30th Apr 2015
• Third Release 1.0.2 - 12th Aug 2016
• Fourth Release 1.1 - 19th Nov 2018
• Fifth Release 1.2 - 04th Jan 2019
1
Page
About Dot Net Tricks
Dot Net Tricks is founded by Shailendra Chauhan (Microsoft MVP), in Jan 2010. Dot Net Tricks came into existence
in form of a blog post over various technologies including .NET, C#, SQL Server, ASP.NET, ASP.NET MVC, JavaScript,
Angular, Node.js and Visual Studio etc.
The company which is currently registered by a name of Dot Net Tricks Innovation Pvt. Ltd. came into the shape
in 2015. Dot Net Tricks website has an average footfall on the tune of 300k+ per month. The site has become a
cornerstone when it comes to getting skilled-up on .NET technologies and we want to gain the same level of trust
in other technologies. This is what we are striving for.
We have a very large number of trainees who have received training from our platforms and immediately got
placement in some of the reputed firms testifying our claims of providing quality training. The website offers you
a variety of free study material in form of articles.
For a beginner who needs regular guidance, we have a fully packed Master Courses. They are almost equal to
semester courses taught in engineering colleges when it comes to length, breadth of content delivery, the only
difference instead of 5-6 months, they take approx. 16-weekend classes (2 months).
Hands-On Learning courses give you the confidence to code and equally helpful to work in real-life scenarios. This
course is composed of hands-on exercise using IDE or cloud labs so that you can practice each and everything by
yourself. You can learn to code at your own pace, time and place.
The detail about Hands-On Learning courses can be found here: https://www.scholarhat.com
Professionals who don’t have two months’ time and want to get skilled up in least possible time due to some new
project that their company has to take in very near future, we have designed Skill Bootcamps Concept, where you
will get trained on consecutive days in a fast-paced manner, where our full focus is going to be on hands-on
delivery of technological exercises.
Self-paced Courses
2
Page
Self-paced courses give you the liberty to study at your own pace, time and place. We understand everyone has
their own comfort zone, some of you can afford to dedicate 2 hours a day, some of you not. Keeping this thing in
mind, we created these self-paced courses. While creating these courses we have ensured that quality of courses
doesn’t get compromise at any parameter, and they also will be able to produce the same results as our other
course formats, given the fact you will be able to put your own honest effort.
Dot Net Tricks having a pool of mentors who help the corporate to enhance their employment skills as per
changing technology landscape. Dot Net Tricks offers customized training programs for new hires and experienced
employees through online and classroom mode. As a trusted and resourceful training partner, Dot Net Tricks helps
the corporate to achieve success with its industry-leading instructional design and customer training initiatives.
Learning Platform
We have a very robust technology platform to answer the needs of all our trainees, no matter which program they
enrolled in. We have a very self-intuitive Learning Management System (LMS), which help you in remain focused
and keeping an eye over your progress.
Apart from these, we also provide on-demand Skill bootcamps and personalized project consultation.
3
Page
Dedication
My mother Mrs Vriksha Devi and my wife Reshu Chauhan deserve to have their name on the cover as
much as I do for all their support made this possible. I would like to say thanks to all my family members
Virendra Singh(father), Jaishree and Jyoti(sisters), Saksham and Pranay(sons), friends, to you and to
readers or followers of my articles at https://www.dotnettricks.com/mentors/shailendra-chauhan to
encourage me to write this book.
-Shailendra Chauhan
4
Page
Introduction
Writing a book has never been an easy task. It takes great effort, consistency with strong determination most
importantly must have wisdom over the subject on which you are going to write.
His inspiration for authoring comes from his enthusiasm for technology, analytic and initiative nature. Being a
trainer, architect and blogger and passion for helping people inspire him for writing.
Enormous feedback and support from his previous books which appreciated by all user inspire him to write
AngularJS interview questions and answers book.
To get the latest release on AngularJS, we encourage you to follow the official AngularJS website at
www.angularjs.org
Our best wishes always with you for your interview and growth!
5
Page
About the Author
Shailendra Chauhan - An Entrepreneur, Author, Architect,
Corporate Trainer, and Microsoft MVP
He is the Founder and CEO of DotNetTricks which is a brand when it comes
to e-Learning. DotNetTricks provides training and consultation over an array
of technologies like Cloud, .NET, Angular, React, Node and Mobile Apps
development. He has been awarded as Microsoft MVP three times in a row
(2016-2018).
He has changed many lives from his writings and unique training programs.
He has a number of most sought-after books to his name which have helped
job aspirants in cracking tough interviews with ease.
Moreover, and to his credit, he has delivered 1000+ training sessions to professionals worldwide in Microsoft
.NET technologies and other technologies including JavaScript, AngularJS, Node.js, React and NoSQL Databases.
In addition, he provides Instructor-led online training, hands-on workshop and corporate training programs.
Shailendra has a strong combination of technical skills and solution development for complex application
architecture with proven leadership and motivational skills have elevated him to a world-renowned status,
placing him at the top of the list of most sought-after trainers.
“I always keep up with new technologies and learning new skills to deliver the best to my students” says
Shailendra Chauhan, he goes on to acknowledge that the betterment of his followers and enabling his students to
realize their goals are his prime objective and a great source of motivation and satisfaction.
Shailendra Chauhan - “Follow me and you too will have the key that opens the door to success”
6
Page
About the Reviewer
Kanishk Puri
Works as a Sr. Software Developer and have around 7 years of experience in
.Net Technology using ASP. Net MVC, LINQ, Entity Framework, Web API,
jQuery, SQL Server, AngularJS and mobile development.
Expert to develop mobile hybrid apps and N-tier web application using latest
platform like PhoneGap, ASP.NET MVC, Entity Framework, Web API,
PhoneGap, AngularJS, jQuery Mobile, Backbone and Ionic.
7
Page
How to Contact Us
Although the author of this book has tried to make this book as accurate as it possible but if there is something
strikes you as odd, or you find an error in the book please drop a line via e-mail.
• [email protected]
• [email protected]
We always happy to hear from our readers. Please provide your valuable feedback and comments!
You can follow us on YouTube, Facebook, Twitter, LinkedIn and Google Plus or subscribe to RSS feed.
8
Page
Table of Contents
AngularJS Interview Questions & Answers .................................................... 1
Release History........................................................................................................................................1
About Dot Net Tricks................................................................................................................................2
Dot Net Tricks Training Solutions ..............................................................................................................2
Dedication ..............................................................................................................................................4
Introduction ............................................................................................................................................5
About the Author ....................................................................................................................................6
About the Reviewer .................................................................................................................................7
How to Contact Us...................................................................................................................................8
Databinding ................................................................................................... 33
Q1. What is data binding in AngularJS? ......................................................................................................... 33
Q2. Explain Two-way and One-way data binding in AngularJS? .................................................................... 33
Q3. What is an issue with two-way data binding? ......................................................................................... 34
Q4. How AngularJS handle data binding? ...................................................................................................... 35
Q5. What are Expressions in AngularJS? ........................................................................................................ 35
Q6. How AngularJS expressions are different from the JavaScript expressions? .......................................... 35
Q7. What is the difference between $watch, $digest and $apply? ............................................................... 35
Q8. Which one is fast between $digest and $apply? ..................................................................................... 37
Q9. Which one handles exception automatically between $digest and $apply? .......................................... 37
Q10. Explain $watch(), $watchgroup() and $watchCollection() functions of scope? ...................................... 38
Q11. Explain AngularJS scope life-cycle? ......................................................................................................... 39
Q12. Explain digest life-cycle in AngularJS? ..................................................................................................... 40
Q13. When to use $destroy() function of scope? ............................................................................................ 41
10
Services ......................................................................................................... 62
Q1. What is Service in AngularJS? .................................................................................................................. 62
Q2. What are different ways to create service in AngularJS? ........................................................................ 62
Q3. What is the difference between Factory, Service and Provider? ............................................................ 62
Q4. What is the difference between value and constant? ............................................................................ 65
Q5. What is $emit, $broadcast and $on in AngularJS? .................................................................................. 65
Q6. What is the difference between $http and $resource? .......................................................................... 69
Q7. What methods $http service support? ................................................................................................... 69
Q8. How to enable caching in $http service? ................................................................................................ 69
Q9. What methods $resource service object support? ................................................................................. 69
Q10. What is $q service and when to use it? ................................................................................................... 70
Q11. What is the difference between Kris Kowal's Q and $q? ........................................................................ 70
Q12. What is Restangular? ............................................................................................................................... 70
Q13. What are the advantages of Restangular over $resource and $http? .................................................... 70
Q14. What is the difference between $window and window in AngularJS? ................................................... 71
12
Q16. What is the difference between $timeout and window.setTimeout in AngularJS? ............................... 72
Q17. What is the difference between $interval and window. setInterval in AngularJS? ................................ 72
References..................................................................................................... 73
13
Page