What is the difference between Angular and Jquery? | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Name the key Features of AngularJS? |
---|
The key features of AngularJS are:
|
Explain Data Bindings in AngularJs |
---|
According to AngularJS.org, “Data-binding in Angular apps is the automatic synchronization of data between the model and view components. The way that Angular implements data-binding lets you treat the model as the single-source-of-truth in your application. The view is a projection of the model at all times. When the model changes, the view reflects the change and vice versa.” There are two ways of data binding:
|
What is AngularJS? |
---|
AngularJS is a JavaScript framework that is used for making rich, extensible web applications. It runs on plain JavaScript and HTML, so you don’t need any other dependencies to make it work.AngularJS is perfect for Single Page Applications (SPA). It is basically used for binding JavaScript objects with HTML UI elements. |
Explain the architecture of AngularJS? |
---|
AngularJS is architecture on 3 components. They are
AngularJS extends HTML attributes with Directives and binds data to HTML with Expressions. |
What is the Template in AngularJS? |
---|
The template is the HTML portion of the angular app. It is exactly like a static HTML page, except that templates contain additional syntax which allows data to be injected in it in order to provide a customized user experience. |
What is the Scope in AngularJS? |
---|
The scope is the object that represents the “model” of your application. It contains fields that store data which is presented to the user via the template, as well as functions which can be called when the user performs certain actions such as clicking a button. |
What is the controller in AngularJS? |
---|
The controller is a function which generally takes an empty scope object as a parameter and adds to it the fields and functions that will be later exposed to the user via the view. |
Explain Directives in AngularJS? |
---|
AngularJS directives are extended HTML attributes with the prefix ng-
|
List some tools for testing AngularJS applications? |
---|
For testing AngularJS applications there are certain tools that you should use that will make testing much easier to set up and run. Karma Karma is a JavaScript command line tool that can be used to spawn a web server which loads your application’s source code and executes your tests. You can configure Karma to run against a number of browsers, which is useful for being confident that your application works on all browsers you need to support. Karma is executed on the command line and will display the results of your tests on the command line once they have run in the browser. Karma is a NodeJS application and should be installed through NPM/YARN. Full installation instructions are available on the Karma website. Jasmine Jasmine is a behavior-driven development framework for JavaScript that has become the most popular choice for testing AngularJS applications. Jasmine provides functions to help with structuring your tests and also making assertions. As your tests grow, keeping them well structured and documented is vital, and Jasmine helps achieve this. Jasmine comes with a number of matches that help you make a variety of assertions. You should read the Jasmine documentation to see what they are. To use Jasmine with Karma, we use the karma-jasmine test runner. angular-mocks AngularJS also provides the ngMock module, which provides mocking for your tests. This is used to inject and mock AngularJS services within unit tests. In addition, it is able to extend other modules so they are synchronous. Having tests synchronous keeps them much cleaner and easier to work with. One of the most useful parts of ngMock is $httpBackend, which lets us mock XHR requests in tests and return sample data instead. |
How do you share data between controllers in AngularJS? |
---|
We can share data by creating a service, Services are easiest, fastest and cleaner way to share data between controllers in AngularJs.
|
Explain AngularJS digest cycle? |
---|
AngularJS digest cycle is the process behind Angular JS data binding. 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. |
What is the internationalization in AngularJS? |
---|
Internationalization is a way to show locale-specific information on a website.It is used to create multilingual language websites. |
Difference between AngularJS and Javascript expressions? |
---|
Below are some major difference between AngularJS and JavaScript Expressions
|
Explain basic steps to set up an Angular App? |
---|
|
What are Angular Modules? |
---|
Angular Modules are place where we write code of our Angular application.Writing Modules makes our code more maintainable, testable, and readable. All dependencies for our app are defined in modules. |
Explain Directive Scopes? |
---|
There are three types of directive scopes available in Angular.
|
Explain the role of $routeProvider in AngularJS? |
---|
The $routeProvider is used to configure roots within an AngularJS application. It can be used to link a URL with a corresponding HTML page or template, and a controller (if applicable). |
Explain how does Angular Implement two-way binding ? |
---|
Data-binding in Angular apps is the automatic synchronization of data between the model and view components. The way that Angular implements data-binding lets you treat the model as the single-source-of-truth in your application. The view is a projection of the model at all times. When the model changes, the view reflects the change and vice versa. |
What is dependency Injection and how does it work? |
---|
AngularJS was designed to highlight the power of dependency injection, a software design pattern that places an emphasis on giving components their dependencies instead of hardcoding them within the component. For example, if you had a controller that needed to access a list of customers, you would store the actual list of customers in a service that can be injected into the controller instead of hardcoding the list of customers into the code of the controller itself. In AngularJS you can inject values, factories, services, providers, and constants. |
What is $rootscope? How is it different from the scope? |
---|
In Angular JS $rootscope and $scope both are an object which is used for sharing data from the controller to view. The main difference between $rootscope and $scope is that $rootscope is available globally to across all the controllers whereas $scope is available only in controllers that have created it along with its children controllers. |
What is the difference between $scope and scope? |
---|
In Angular js $scope is used whenever we have to use dependency injection (D.I) whereas as the scope is used for directive linking. |
What are Angular Expressions? |
---|
Angular js Expression is JavaScript alike code snippets used to bind expression data in view or HTML. Angular expressions are written inside two curly braces. {{a+b}} |
List some of the built-in validators in Angular JS? |
---|
Angular js supports all standard HTML5 attributes to validate input.Below are few built-in validators in Angular js.
|
What is Angular's prefixes $ and $$? |
---|
Angular uses these prefixes to prevent accidental code collision with users code. $ prefix is used with public objects whereas $$ prefix is used with a private object. |
What are directives? How to create and use custom Directive in Angular JS? |
---|
In angular Directives are used to extend the attributes of Html elements.
As Above directive is restricted to Element directive, so you can use this directive as an element only. |
How to isolate a directives Scope in Angular? |
---|
You can isolate a directive’s Scope by passing an object to the scope option of directive. This tells the directive to keep scope inside of itself and not to inherit or share with other scopes. |
What is the difference between one-way binding and two-way binding? |
---|
In One-Way data binding, view (UI part) not updates automatically when data model changed. We need to write custom code to make it updated every time. While in two way binding scope variable will change it’s value every time its data model changed is assigned to a different value. |
What are the directives in AngularJS? |
---|
A core feature of AngularJS, directives are attributes that allow you to invent new HTML syntax, specific to your application. 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. The different types of directives are:
|
What are controllers in AngularJS? |
---|
Controllers are Javascript functions which provide data and logic to HTML UI. As the name suggests, they control how data flows from the server to HTML UI. |
How to access parent scope from child scope in AngularJS? |
---|
In angular there is a scope variable called $parent (i.e. $scope.$parent). $parent is used to access parent scope from child controller in Angular JS.
|
How to do email and Phone No. validation in Angular JS? |
---|
Angular form validation and ng-pattern directive can be used to validate the email and phone number in Angular JS. |
What is the difference between a link and compiler in Angular JS? |
---|
Compile function: To template DOM manipulation and to gather all the directives, the compile function is used. Link function: To register DOM listeners as well as for the instance DOM manipulation, the Link function is used. |
How can you get URL parameters in Controller? |
---|
The RouteProvider and the RouteParams can be used to get the URL parameters in the controller. As the route wires up the URL to the controller and RouteParams can be passed to the controller to get the URL parameters. |
How to enable caching in Angular 1.x? |
---|
Caching can be enabled by setting the config.cache value or the default cache value to TRUE or to a cache object that is created with $cacheFactory. In case you want to cache all the responses, then you can set the default cache value to TRUE. And, if you want to cache a specific response, then you can set the config.cache value to TRUE. |
Explain the use of Ng-if, Ng-Switch and Ng-Repeat directives? |
---|
ng-if – This directive removes a portion of the DOM tree, which is based on the expression. In case the expression is assigned to ng-if, it evaluates to a false value, and then the element is deleted from the DOM tree, or else a clone of the element is reinserted into the DOM. ng-switch – This directive is used based on a scope expression to conditionally swap DOM structure on the template. The ng-switch default directive will be preserved at the specific location in a template. ng-repeat – This directive is used to instantiate the template once per item from a collection. Each template which is instantiated gets its own scope where the given loop variable is set to the current collection of item. |
List some differences between Angular JS and Angular 2? | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
What is $emit,$broadcast and $on in Angular JS? |
---|
$broadcast, $emit, and $on are services in Angular Js. Below we have listed why they are used In Angular JS. $broadcast(): $broadcast() service of Angular is used to propagate the event to all of his child controllers and it’s registered parent $rootscope.scope listeners. $rootScope.$broadcast('SummaryEvent', { priority: priority }); $on(): AngularJS $on() service is used to listen any type of event raised by $broadcast and $emit. $scope.$on(''SummaryEvent'', function (event, args) { Vm.priority=args.priority }); $emit: $emit is similar to $broadcast service but it is used to propagate the event to upwards through the scope hierarchy and notify to the registered $rootScope.Scope listeners. |
What is Angular Expressions? How do you differentiate between Angular expressions and Javascript expressions? |
---|
Angular expressions are code snippets that are usually placed in binding such as {{ expression }} similar to JavaScript. The main differences between Angular expressions and JavaScript expressions are:
|
What is the difference between link and compile in AngularJS? |
---|
|
What are the characteristics of 'Scope?' |
---|
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. The characteristics of Scope are:
|
What are the advantages of using Angular.js framework? |
---|
Angular.js framework has the following advantages:
|
What is the difference between AngularJS and backbone.js? |
---|
AngularJS combines the functionalities of most third party libraries and supports individual functionalities required to develop HTML5 Apps. While Backbone.js does these jobs individually. |
Explain what is Injector in JS? |
---|
An injector is a service locator, used to retrieve object instance as defined by provider, instantiate types, invoke methods, and load modules. |
What is factory method in AngularJS? |
---|
Factory method is used for creating a directive. It is invoked when the compiler matches the directive for the first time. We can invoke the factory method using $injector.invoke. Syntax: |
What is ng-app, ng-init and ng-model? |
---|
|
Does Angular uses the Jquery library? |
---|
Yes, Angular can use jQuery if it’s present in the app when the application is being bootstrapped. If jQuery is not present in the script path, Angular falls back to its own implementation of the subset of jQuery that we call jQLite. |
Can AngularJS have multiple ng-app directives in a single App? |
---|
No. Only one AngularJS application can be auto-bootstrapped per HTML document. The first ngApp found in the document will be used to define the root element to auto-bootstrap as an application. If another ng-app directive has been placed then it will not be processed by AngularJS and we will need to manually bootstrap the second app, instead of using second ng-app directive. |
Can angular applications (ng-app) be nested within each other? |
---|
No. AngularJS applications cannot be nested within each other. |
What is internationalization and how to implement it in AngularJS? |
---|
Internationalization is a way in which you can show locale specific information on a website. AngularJS supports inbuilt internationalization for three types of filters: currency, date and numbers. To implement internalization, we only need to incorporate corresponding js according to locale of the country. By default it handles the locale of the browser. |
On which types of component can we create a custom directive? |
---|
AngularJS provides support to create custom directives for the following:
|
What is $rootscope in AngularJS? |
---|
Every application has a single root scope. All other scopes are descendant scopes of the root scope. Scopes provide separation between the model and the view, via a mechanism for watching the model for changes. They also provide event emission/broadcast and subscription facility. |
Can we have nested controllers in AngularJS? |
---|
Yes, we can create nested controllers in AngularJS. Nested controllers are defined in hierarchical manner while using in View. |
What is bootstrapping in AngularJS? |
---|
Bootstrapping in AngularJS is nothing but initializing, or starting the Angular app. AngularJS supports automatic and manual bootstrapping.
|
What does SPA(Single Page Application) mean? How can we implement with SPA with Angular? |
---|
Single Page Applications (SPAs) are web apps that load a single HTML page and dynamically update that page as the user interacts with the app. In an SPA the page never reloads, though parts of the page may refresh. This reduces the round trips to the server to a minimum. It’s a concept where we create a single shell page or master page and load the webpages inside that master page instead of loading pages from the server by doing post backs. We can implement SPA with Angular using Angular routes. You can read up about SPAs here. |
Why AngularJS? |
---|
AngularJS lets us extend HTML vocabulary for our application resulting in an expressive, readable, and quick to develop environment . Some of the advantages are:
|
Is AngularJS compatible with all Browsers? |
---|
Yes AngularJS is compatible with the following browsers: Safari, Chrome, Firefox, Opera 15, IE9 and mobile browsers (Android, Chrome Mobile, iOS Safari). |
How to implement routing in AngularJS? |
---|
It is a five-step process:
|
Explain $q service, deferred and promises? |
---|
|