Interview Questions Flashcards
What is an expression in Angular?
Expressions are used to bind data to the view (double curly brackets)
What is the difference between “==” and “===” ?
-double equals compares two types
-triple equals compares types and values
ex, “2” == 2; //true
“2” === 2; //false
What are the differences between null and undefined?
null is an object with no value
undefined is a type
What are some of the core directives in Angular?
ng-app
ng-model
ng-bind
How would you improve page runtime performance as your application scales?
- to achieve 60 frames per second to keep up with your refresh rate you have about 16 milli seconds for your code to execute jank-free. I would keep an eye on concurrent watches and try to keep the $watch count preferably under 2,000 because Angular is known to drastically slow down in performance time whenever your application does dirty checking and you have more than 2 - 2,500 digest cycles happening.
- use one-time binding w/ double colon syntax
- Debouncing ng-model updates in your ngModelOptions
- Try and reduce ng-repeat
- Avoid filters if possible because they run twice per digest cycle. Use $filterProvider instead because it will run filters in your javascript code before parsing it into the DOM
- Use ng-if instead of ng-show or ng-hide. ng-if scopes are destroyed and a new scope is created whenever the conditional is met, whereas, ng-show and ng-hide simply masks the elements with css and takes more processing power
How do you share data between controllers?
- Services are the cleanest, fastest, and easiest way
- events - event listeners
- $rootScope - but you want to avoid using at all cost unless you absolutely have to.
What is a digest cycle in Angular?
a digest cycle compares old and new scoped model values
When does a digest cycle happen?
it happens whenever a new event is set off
What is the difference between one-way binding and two-way binding?
- one way binding implies that the scope variable in the html will be set to the first value it’s model is bound or assigned to
- two-way binding the scoped variable changes it’s value everytime its model is assigned a new value
How does $scope.$apply() work?
it looks at all the declared models and forces or applies the change to any model that have been altered. but its a bad practice it forces angular to run on all entire models and variable but sometimes necessary when dealing with third party plugins and when you’re dealing with timing issues.
Explain data binding in Angular.
Data synchronization between the model and view components. The view is a projection of the model at all times. When the model changes, the view reflects the change, and vice versa.”
What are directives?
They are essentially functions that execute when the Angular compiler finds them in the DOM. Some of the most commonly used directives are ng-app,ng-controller and ng-repeat.
What are controllers in Angular?
Controllers are Javascript functions which provide data and logic to the view. As the name suggests, they control how data flows from the server to view.
What is the difference between link and compile in Angular?
- The compile function is used for template DOM manipulation and to collect all directives.
- Link function is used for registering DOM listeners as well as instance DOM manipulation and is executed once the template has been cloned.
Explain what is Injector in Angular.
An injector is a service locator, used to retrieve object instance as defined by provider, instantiate types, invoke methods, and load modules.