Skip to content

Instantly share code, notes, and snippets.

@cminhho
Last active June 17, 2018 10:06
Show Gist options
  • Save cminhho/cb1f78cadbfbc5613a0faec56ae11564 to your computer and use it in GitHub Desktop.
Save cminhho/cb1f78cadbfbc5613a0faec56ae11564 to your computer and use it in GitHub Desktop.
AngularJS_Interview_Question_And_Answer
What is AngularJS?
- AngularJS is an open-source JS framework
- Developed by Google
- Designed for creating dynamic single page applications with fewer lines of code.
Advantages of AngularJS?
- It uses MVC design pattern which allows you separate an application into different components, thus making easy to maintain.
- Allows to create dynamic template, as new attribute, elements.
- 2 ways binding data - enables automatic synchronization data between model and view, so there is no need to add any JS code or event listeners to reflect the data changes
- Re-usable code - it allows the creation of user-defined directives and reusable components.
- It has a big community to help the developers.
What is the main thing that you need to change if you were migrating from AngularJS 1.4 to AngularJS 1.5?
- Change the way to define a new component by using .directive to .component.
What are the main features of AngularJS?
- Data-binding - handles synchronization data across model, view and controllers
- Scope - An object presenting the model, acts as a glue layer between view and controller (contains the model datas) Scope is an object that refers to the application model.
- Controllers - to control the flow of data in the application
- Services -
- Filters - to transform/change data before pasing it to the view, ex: uppercase, lowercase, date, ...
- Directives - to extend HTML with new attributes
- Templates - HTML code including in AngularJS specific elements and attributes
- Routing - It's an approach to switch views.
- MVC: Model - represents data. View renders data for the user. Controller gives control over the model and view for collating information to the user
- Dependency injection - A design pattern to let the components injected into each other as dependencies.
What browsers do Angular support?
- AngularJs works fine with latest version of Chrome, FF, IE 9 and Safari
- Version 1.3 or later of Angular dropped suport for IE8
What are the Web App security risks that a web deverloper should avoid while doing development using AngularJS
- Broken Authentication and session management
-
Explain what directives are? Mention some of most commonly used directives in Angular application
- AngularJS extends the behavior of HTML and DOM elements with new atributes.
- ng-bind: tells AngularJS to replace the content of element with value of a given variable or expression.
- ng-model: used to bind the value of HTML control (input, select, text area) to applicatoin. it supports 2way binding data.
- ng-class: used to bind CSS classes to an HTML element.
- ng-app - to make the begining of the application to AngularJS's HTML compiler.
- ng-init - to initialize (iˈniSHəˌlīz) the application data
- ng-repeat - repeats a set of HTML statements
What are expressions in AngularJS?
- binds datas to HTML
- can include literals (String / Context), operators and variables
What are different ways to invoke a directive?
- 4 different ways to invoke a directive in an application
- As an Attribute
- As a Class
- As an Element
- As a Comment
What is singleton pattern? How does Angular use it?
- is an approach that we adopt/accept to limit the instantiation of a Class to have only one object. In AngularJS, the dependency injection and the serivces implement are the singlleton pattern.
What is $scope in AngularJS
- is an application object. as the owner of the apps variables and functions. Scope object has access to both View and Controller.
- it provides observers/watcher to watch for all the model changes.
What is $rootScope in AngularJS?
- Every AngularJS app has a $rootscope which will be shared to all componens.
What is SPA in AngularJS?
- are web applicatoins that fit on a single HTML page. It dynamically updates the web apps as ...
Explain the directive ng=if, ng-switch, and ng-repeat?
- <ng-if> adds a copy of HTML elements to the DOM if the expression is true. otherwise, remove the HTML elements form the DOM.
- <ng-repeat> to loop/iterate over a collection of items and generate HTML from it.
What is a factory method in AngularJS?
- create a new object and add functions as property of this object and at the end we return this object.
- it is an collection of functions
What would you do to limit a scope variable to have on-time biding?
- Adds prefixing "::" (double colons) operation to the scope variable.
How to implement routing in AngularJS?
Step 1: – Add the “Angular-route.js” file to your view.
Step 2: – Inject “ngroute” functionality while creating Angular app object.
Step 3: – Configure the route provider.
Step 4: – Define hyperlinks.
Step 5: – Define sections where to load the view.
Explain how $scope.$apply() works?
re-avaluates all declared ng-model and applies the changes have been altered
What makes the angular.copy() method so powerful?
- A deep copy of a variable.
- does not point to the same memory reference as that variable.
Note: usally assigning one variable to another creates a "shallow copy", which makes the two variable point to the same memory referance. Therefor if one is changed, the other changes as well.
How do you share data between controllers?
– Create an AngularJS service that will hold the data and inject it inside of the controllers.
– Using events
– Using $parent, nextSibling, controllerAs, etc. to directly access the controllers
– Using the $rootScope to add the data on (not a good practice)
What is the difference between ng-show/ng-hide and ng-if directives?
- ng-show/ng-hide will always insert the DOM element
- ng-if is better when we needed the DOM to be loaded conditionally, as it will help load page bit faster compared to ng-show/ng-hide.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment