250 likes | 262 Views
In this PPT you are going to know about What are some AngularJS interview questions? <br><br>Meet The Experts : https://nareshit.com/angularjs-online-training/
E N D
Explain what is a $scope in Angular JS ? • Scope is an object that refers to the application model. It is an execution context for expressions. Scopes are arranged in hierarchical structure which mimic the DOM structure of the application. Scopes can watch expressions and propagate events. Scopes are objects that refer to the model. They act as glue between controller and view. • This question is important as it will judge a persons knowledge about a $scope object, and it is one of the most important concepts in AngularJS. Scope acts like a bridge between view and model.
Explain Angular JS boot process? • When the page is loaded in the browser, following things happen: • HTML document is loaded into the browser, and evaluated by the browser. AngularJS JavaScript file is loaded; the angular global object is created. Next, JavaScript which registers controller functions is executed. • Next AngularJS scans through the HTML to look for AngularJS apps and views. Once view is located, it connects that view to the corresponding controller function. • Next, AngularJS executes the controller functions. It then renders the views with data from the model populated by the controller. The page gets ready.
What is MVC ? • Model View Controller or MVC as it is popularly called, is a software design pattern for developing web applications. A Model View Controller pattern is made up of the following three parts: • Model - It is the lowest level of the pattern responsible for maintaining data. • View - It is responsible for displaying all or a portion of the data to the user. • Controller - It is a software Code that controls the interactions between the Model and View.
How does interpolation, e.g. “{{ someModel }}”, actually work? • It relies on $interpolation, a service which is called by the compiler. It evaluates text and markup which may contain AngularJS expressions. For every interpolated expression, a “watch()” is set. $interpolation returns a function, which has a single argument, “context”. By calling that function and providing a scope as context, the expressions are “$parse()”d against that scope.
How do you share data between controllers? • Using a service is the cleanest, fastest and easiest way to test. • However, there are couple of other ways to implement data sharing between controllers, like: • – 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, but will display/hide it based on the condition. ng-if will not insert the DOM element until the condition is not fulfilled. • 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. • We only need to keep in mind what the difference between these directives is, so deciding which one to use totally depends on the task requirements.
What is a digest cycle in AngularJS? • In each digest cycle Angular compares the old and the new version of the scope model values. The digest cycle is triggered automatically. We can also use $apply() if we want to trigger the digest cycle manually. • Some people think initially, that Angular has a kind of poll mechanism that checks every few milliseconds if something on the model changed so it can update the view accordingly. This is not true. • There are basically three possible cases when the state of an application can change and these are the only moments where $digest cycles are needed. The case are: • User Interaction through events - The user clicks UI controls like buttons and in turn triggers something in our application that changes state. • XMLHttpRequests - Also known as AJAX. Something in our app requests some data from a server and update model data accordingly. • Timeouts - Asynchronous operations cause through timers that can possibly change the state of our application • Where should we implement the DOM manipulation in AngularJS? • In the directives. DOM Manipulations should not exist in controllers, services or anywhere else but in directives.
Is it a good or bad practice to use AngularJS together with jQuery? • It is definitely a bad practice. We need to stay away from jQuery and try to realize the solution with an AngularJS approach. jQuery takes a traditional imperative approach to manipulating the DOM, and in an imperative approach, it is up to the programmer to express the individual steps leading up to the desired outcome. • AngularJS, however, takes a declarative approach to DOM manipulation. Here, instead of worrying about all of the step by step details regarding how to do the desired outcome, we are just declaring what we want and AngularJS worries about the rest, taking care of everything for us.
How would you specify that a scope variable should have one-time binding only? • By using “::” in front of it. This allows the check if the candidate is aware of the available variable bindings in AngularJS. • 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 its model is bound to (i.e. assigned to) • – Two way binding implies that the scope variable will change it’s value everytime its model is assigned to a different value
Explain how $scope.$apply() works • $scope.$apply re-evaluates all the declared ng-models and applies the change to any that have been altered (i.e. assigned to a new value) • Explanation: $scope.$apply() is one of the core angular functions that should never be used explicitly, it forces the angular engine to run on all the watched variables and all external variables and apply the changes on their values.
What makes the angular.copy() method so powerful? • It creates a deep copy of the variable. • A deep copy of a variable means it doesn’t point to the same memory reference as that variable. Usually assigning one variable to another creates a “shallow copy”, which makes the two variables point to the same memory reference. Therefore if we change one, the other changes as well
What is a singleton pattern and where we can find it in Angularjs? • Is a great pattern that restricts the use of a class more than once. We can find singleton pattern in angular in dependency injection and in the services. • In a sense, if you do 2 times ‘new Object()‘ without this pattern, you will be alocating 2 pieces of memory for the same object. With singleton pattern, if the object exists, you reuse it
What is an interceptor? What are common uses of it? • An interceptor is a middleware code where all the $http requests go through. • The interceptor is a factory that are registered in $httpProvider. You have 2 types of requests that go through the interceptor, request and response (with request Error and response Errorrespectively). This piece of code is very useful for error handling, authentication or middleware in all the requests/responses.
How would you programatically change or adapt the template of a directive before it is executed and transformed? • You would use the compile function. The compile function gives you access to the directive’s template before transclusion occurs and templates are transformed, so changes can safely be made to DOM elements. This is very useful for cases where the DOM needs to be constructed based on runtime directive parameters.
How to angular scope from outside javascript function ? • var element = document.querySelector('[ng-controller=“controller”]’); • //can be used any selector scope will be the scope inside that selector • var $scope = angular.element(element).scope();
How Browser Works, what happens, exactly? • When you type a web address into your browser (for our analogy that's like walking to the shop): • The browser goes to the DNS server, and finds the real address of the server that the website lives on (you find the address of the shop). • The browser sends an HTTP request message to the server, asking it to send a copy of the website to the client (you go to the shop and order your goods). This message, and all other data sent between the client and the server, is sent across your internet connection using TCP/IP. • Provided the server approves the client's request, the server sends the client a "200 OK" message, which means "Of course you can look at that website! Here it is", and then starts sending the website's files to the browser as a series of small chunks called data packets (the shop gives you your goods, and you bring them back to your house). • The browser assembles the small chunks into a complete website and displays it to you (the goods arrive at your door — new shiny stuff, awesome!).
What is ReST services? • Representational State Transfer (REST) is an architectural style that specifies constraints, such as the uniform interface, that if applied to a web service induce desirable properties, such as performance, scalability, and modifiability, that enableservices to work best on the Web.
What is a ReST end point? • In REST, the resource typically refers to some object or set of objects that are exposed at an API endpoint. /api/users/johnny. An endpoint by itself is just a reference to a uri that accepts web requests that may or may not be RESTful. /services/service.asmx
What is the ReST protocol? • REST stands for Representational State Transfer. (It is sometimes spelled "ReST".) It relies on a stateless, client-server, cacheable communications protocol -- and in virtually all cases, the HTTP protocol is used. REST is an architecture style for designing networked applications.
What is meant by the term “RESTful API”? • Conforming to the REST constraints is generally referred to as being “RESTful” • An API can be considered “RESTful” if it has the following features (not a complete list just the main ones): • Client–server – The client handles the front end the server handles the backend and can both be replaced independently of each other. • Stateless – No client data is stored on the server between requests and session state is stored on the client. • Cacheable – Clients can cache response (just like browsers caching static elements of a web page) to improve performance. • Complying with these constraints, and thus conforming to the REST architectural style enables any kind of distributed hypermedia system to have desirable emergent properties, such as performance, scalability, simplicity, modifiability, visibility, portability, and reliability. A common trend I have seen is to use absolute urls for RESTful APIs which are meaningful.
What Are Cookies? What is a Cookie? • Cookies are small files which are stored on a user's computer. They are designed to hold a modest amount of data specific to a particular client and website, and can be accessed either by the web server or the client computer. This allows the server to deliver a page tailored to a particular user, or the page itself can contain some script which is aware of the data in the cookie and so is able to carry information from one visit to the website (or related site) to the next.
What's in a Cookie? • Each cookie is effectively a small lookup table containing pairs of (key, data) values - for example (firstname, John) (lastname, Smith). Once the cookie has been read by the code on the server or client computer, the data can be retrieved and used to customise the web page appropriately.
Why are Cookies Used? • Cookies are a convenient way to carry information from one session on a website to another, or between sessions on related websites, without having to burden a server machine with massive amounts of data storage. Storing the data on the server without using cookies would also be problematic because it would be difficult to retrieve a particular user's information without requiring a login on each visit to the website. • If there is a large amount of information to store, then a cookie can simply be used as a means to identify a given user so that further related information can be looked up on a server-side database. For example the first time a user visits a site they may choose a username which is stored in the cookie, and then provide data such as password, name, address, preferred font size, page layout, etc. - this information would all be stored on the database using the username as a key. Subsequently when the site is revisited the server will read the cookie to find the username, and then retrieve all the user's information from the database without it having to be re-entered.
Meet The Experts : • https://nareshit.com/angularjs-online-training/