AngularJS Flashcards

1
Q

What is AngularJS?

A

AngularJS is an MVC framework for building web applications. The core features include HTML enhanced with custom component and data-binding capabilities, dependency injection and strong focus on simplicity, testability, maintainability and boiler-plate reduction.

AngularJS is a powerful JavaScript based development framework to create RICH Internet Application (RIA).

AngularJS provides developers options to write client side application (using JavaScript) in a clean MVC (Model View Controller) way.

Application written in AngularJS is cross-browser compliant. AngularJS automatically handles JavaScript code suitable for each browser.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are Directives?

A

At a high level, directives are markers on a DOM element (such as an attribute, element name, comment or CSS class) that tell AngularJS’s HTML compiler ($compile) to attach a specified behavior to that DOM element (e.g. via event listeners), or even to transform the DOM element and its children.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are AngularJS Prefixes $ and $$ for?

A

To prevent accidental name collisions with your code, AngularJS prefixes names of public objects with $ and names of private objects with $$

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is data binding in AngularJS?

A

Data binding is the automatic synchronization of data between model and view components. ng-model directive is used in data binding.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is scope in AngularJS?

A

Scopes are objects that refer to the model. They act as glue between controller and view.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the controllers in AngularJS?

A

Controllers are JavaScript functions that are bound to a particular scope. They are the prime actors in AngularJS framework and carry functions to operate on data and decide which view is to be updated to show the updated model based data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the services in AngularJS?

A

AngularJS come with several built-in services. For example $https: service is used to make XMLHttpRequests (Ajax calls). Services are singleton objects which are instantiated only once in app.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the filters in AngularJS?

A

Filters select a subset of items from an array and return a new array. Filters are used to show filtered items from a list of items based on defined criteria.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain directives in AngularJS.

A

Directives are markers on DOM elements (such as elements, attributes, css, and more). These can be used to create custom HTML tags that serve as new, custom widgets. AngularJS has built-in directives (ng-bind, ng-model, etc) to perform most of the task that developers have to do.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Explain templates in AngularJS.

A

Templates are the rendered view with information from the controller and model. These can be a single file (like index.html) or multiple views in one page using “partials”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is routing in AngularJS?

A

It is concept of switching views. AngularJS based controller decides which view to render based on the business logic.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the advantages of AngularJS?

A

AngularJS provides capability to create Single Page Application in a very clean and maintainable way.

AngularJS provides data binding capability to HTML thus giving user a rich and responsive experience.

AngularJS code is unit testable.

AngularJS uses dependency injection and make use of separation of concerns.

AngularJS provides reusable components.

With AngularJS, developer writes less code and gets more functionality.

In AngularJS, views are pure html pages, and controllers written in JavaScript do the business processing.

AngularJS applications can run on all major browsers and smart phones including Android and iOS based phones/tablets.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the disadvantages of AngularJS?

A

Not Secure − Being JavaScript only framework, application written in AngularJS are not safe. Server side authentication and authorization is must to keep an application secure.

Not degradable − If your application user disables JavaScript then user will just see the basic page and nothing more.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which are the core directives of AngularJS?

A

ng-app − This directive defines and links an AngularJS application to HTML.

ng-model − This directive binds the values of AngularJS application data to HTML input controls.

ng-bind − This directive binds the AngularJS Application data to HTML tags.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Explain AngularJS boot process.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is MVC?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Explain ng-app directive.

A

ng-app directive defines and links an AngularJS application to HTML. It also indicate the start of the application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Explain ng-model directive.

A

ng-model directive binds the values of AngularJS application data to HTML input controls. It creates a model variable which can be used with the html page and within the container control( for example, div) having ng-app directive.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Explain ng-bind directive.

A

ng-bind directive binds the AngularJS Application data to HTML tags. ng-bind updates the model created by ng-model directive to be displayed in the html tag whenever user input something in the control or updates the html control’s data when model data is updated by controller.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Explain ng-controller directive.

A

ng-controller directive tells AngularJS what controller to use with this view. AngularJS application mainly relies on controllers to control the flow of data in the application. A controller is a JavaScript object containing attributes/properties and functions. Each controller accepts $scope as a parameter which refers to the application/module that controller is to control.

21
Q

How AngularJS integrates with HTML?

A

Step 1 − Include angularjs javascript libray in the html page
script src = “https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js”

Step 2 − Point to AngularJS app

Next we tell what part of the HTML contains the AngularJS app. This done by adding the ng-app attribute to the root HTML element of the AngularJS app. You can either add it to html element or body element as shown below:

body ng-app = “myapp”

22
Q

Explain ng-init directive.

A

ng-init directive initializes an AngularJS Application data. It is used to put values to the variables to be used in the application.

23
Q

Explain ng-repeat directive.

A

ng-repeat directive repeats html elements for each item in a collection.

24
Q

What are AngularJS expressions?

A

Expressions are used to bind application data to html. Expressions are written inside double braces like {{ expression}}. Expressions behave in same way as ng-bind directives. AngularJS application expressions are pure JavaScript expressions and outputs the data where they are used.

25
Q

Explain ng-show directive.

A

ng-show directive shows a given control.

26
Q

Explain ng-hide directive.

A

ng-hide directive hides a given control.

27
Q

Explain ng-click directive.

A

ng-click directive represents a AngularJS click event.

28
Q

How angular.module works?

A

angular.module is used to create AngularJS modules along with its dependent modules.

var mainApp = angular.module("mainApp", []);
Here we've declared an application mainApp module using angular.module function. We've passed an empty array to it. This array generally contains dependent modules declared earlier.
29
Q

How to validate data in AngularJS?

A

AngularJS enriches form filling and validation. We can use $dirty and $invalid flags to do the validations in seamless way. Use novalidate with a form declaration to disable any browser specific validation.

Following can be used to track error.

$dirty − states that value has been changed.

$invalid − states that value entered is invalid.

$error − states the exact error.

30
Q

Explain ng-include directive.

A

Using AngularJS, we can embed HTML pages within a HTML page using ng-include directive.

div ng-app = “” ng-controller = “studentController”
div ng-include = “‘main.htm’”
div ng-include = “‘subjects.htm’”

31
Q

How to make an ajax call using Angular JS?

A

AngularJS provides $https: control which works as a service to make ajax call to read data from the server. The server makes a database call to get the desired records. AngularJS needs data in JSON format. Once the data is ready, $https: can be used to get the data from server in the following manner:

function studentController($scope,$https:) {
   var url = "data.txt";
   $https:.get(url).success( function(response) {
      $scope.students = response; 
   });
}
32
Q

What is use of $routeProvider in AngularJS?

A

$routeProvider is the key service which set the configuration of urls, maps them with the corresponding html page or ng-template, and attaches a controller with the same.

33
Q

What is $rootScope?

A

Scope is a special JavaScript object which plays the role of joining controller with the views. Scope contains the model data. In controllers, model data is accessed via $scope object. $rootScope is the parent of all of the scope variables.

34
Q

What is a service?

A

Services are JavaScript functions and are responsible to do specific tasks only. Each service is responsible for a specific task for example, $https: is used to make ajax call to get the server data. $route is used to define the routing information and so on. Inbuilt services are always prefixed with $ symbol.

35
Q

Is AngularJS extensible?

A

Yes! In AngularJS we can create custom directive to extend AngularJS existing functionalities.

Custom directives are used in AngularJS to extend the functionality of HTML. Custom directives are defined using “directive” function. A custom directive simply replaces the element for which it is activated. AngularJS application during bootstrap finds the matching elements and do one time activity using its compile() method of the custom directive then process the element using link() method of the custom directive based on the scope of the directive.

36
Q

On which types of component can we create a custom directive?

A

AngularJS provides support to create custom directives for following type of elements.

Element directives − Directive activates when a matching element is encountered.

Attribute − Directive activates when a matching attribute is encountered.

CSS − Directive activates when a matching css style is encountered.

Comment − Directive activates when a matching comment is encountered.

37
Q

What are the core features of AngularJS?

A
DATA BINDING
SCOPE
CONTROLLER
SERVICES
FILTERS
DIRECTIVES
TEMPLATES
ROUTING
MODEL VIEW CONTROLLER
DEEP LINKING
DEPENDENCY INJECTION
38
Q

What is AngularJS Data Binding?

A

Data-binding − It is the automatic synchronization of data between model and view components.

39
Q

What is AngularJS Scope?

A

Scope − These are objects that refer to the model. They act as a glue between controller and view.

40
Q

What is AngularJS Controller?

A

Controller − These are JavaScript functions that are bound to a particular scope.

41
Q

What is AngularJS Service?

A

Services − AngularJS come with several built-in services for example $https: to make a XMLHttpRequests. These are singleton objects which are instantiated only once in app.

42
Q

What is AngularJS Filter?

A

Filters − These select a subset of items from an array and returns a new array.

43
Q

What is AngularJS Directives?

A

Directives − Directives are markers on DOM elements (such as elements, attributes, css, and more). These can be used to create custom HTML tags that serve as new, custom widgets. AngularJS has built-in directives (ngBind, ngModel…)

44
Q

What is AngularJS Templates?

A

Templates − These are the rendered view with information from the controller and model. These can be a single file (like index.html) or multiple views in one page using “partials”.

45
Q

What is AngularJS Routing?

A

Routing − It is concept of switching views.

46
Q

What is AngularJS Model View Controller?

A

Model View Whatever − MVC is a design pattern for dividing an application into different parts (called Model, View and Controller), each with distinct responsibilities. AngularJS does not implement MVC in the traditional sense, but rather something closer to MVVM (Model-View-ViewModel). The Angular JS team refers it humorously as Model View Whatever.

47
Q

What is AngularJS Deep Linking?

A

Deep Linking − Deep linking allows you to encode the state of application in the URL so that it can be bookmarked. The application can then be restored from the URL to the same state.

48
Q

What is AngularJS Dependency Injection?

A

Dependency Injection − AngularJS has a built-in dependency injection subsystem that helps the developer by making the application easier to develop, understand, and test.