What is AngularJS?
AngularJS is a one of the most used JavaScript framework to build large scale and high performance web application while keeping them as easy-to-maintain. 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. AngularJS is open source, completely free, and used by thousands of developers around the world. It is licensed under the Apache License version 2.0.
Why AngularJS?
Angularjs is most used and popular frameworks available today. Angular is the next generation framework where each tool was designed to work with every other tool in an interconnected today. Some reasons are why use Angularjs
- MVC pattern
- A declarative user interface with HTML
- Integration
- Data models are POJO
- Less coding used
- Security
- Two way Data binding
- DOM manipulations
- Active community on Google
- Unit Testing
- Best service providers
- Filters and Routing
What are the Core features of AngularJS?
The Core features of angular.js are
- Data Binding
- Scope
- Model
- View
- Controller
- Services
- Directives
- Modules
- Filters
- Testable
- Routing
- Deep linking
- Dependency injection
What are the advantages of using AngularJS framework?
Advantages of using Angular.js as a framework are
- MVC pattern
- Less code and more functionality
- Two way data-binding
- Static template and angular template
- Can add custom directive
- Reusable components
- REST full services
- Form validations
- Unit testable
- Support both client and server communication
- Support dependency injection
- Applying Animations
- Event Handlers
Can you explain data binding in AngularJS?
Data binding is the automatic synchronization of data between model and view components. ng-model directive is used in data binding. There are two ways for data binding
- Data mining in classical template systems
- Data binding in angular templates
Can you define scope?
Scope refers to the application model; it acts like glue between application controller and the view. Scopes are arranged in hierarchical structure and impersonate the DOM (Document Object Model) structure of the application. It can watch expressions and propagate events.
Can you explain services in AngularJS?
Services are the singleton objects or functions that are used for carrying out specific tasks. It holds some business logic and these function can be called as controllers, directive, and filters and so on. 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.
Can you explain Angular Expression?
Like JavaScript, Angular expressions are code snippets that are usually placed in binding such as {{ expression }}
The key difference between the JavaScript expressions and Angular expressions
- Context: In Angular, the expressions are evaluated against a scope object, while the JavaScript expressions are evaluated against the global window
- Forgiving: In Angular expression evaluation is forgiving to null and undefined, while in Java script undefined properties generates Type Error or Reference Error
- No Control Flow Statements: Loops, conditionals or exceptions cannot be used in an angular expression
- Filters: To format data before displaying it you can use filters
What are the most used directives in AngularJS?
A directive is something that introduces new syntax; they are like markers on DOM element which attaches a special behavior to it. In any Angular.js application, directives are the most important components.
Some of the commonly used directives are ng-model, ng-App, ng-bind, ng-repeat , ng-show etc.
ng-app:Auto bootstrap AngularJS application.
ng-initInitializes:AngularJS variables
ng-model:Binds HTML control’s value to a property on the $scope object.
ng-controller:Attaches the controller of MVC to the view.
ng-bind:Replaces the value of HTML control with the value of specified AngularJS expression.
ng-repeat:Repeats HTML template once per each item in the specified collection.
ng-show:Display HTML element based on the value of the specified expression.
ng-readonly:Makes HTML element read-only based on the value of the specified expression.
ng-disabled:Sets the disable attribute on the HTML element if specified expression evaluates to true.
ng-if:Removes or recreates HTML element based on an expression.
ng-click:Specifies custom behavior when an element is clicked.
Can you explain string interpolation in AngularJS?
In AngularJS the compiler during the compilation process matches text and attributes using interpolate service to see if they contains embedded expressions. As part of normal digest cycle these expressions are updated and registered as watches.
script framework used for creating single web page applications. It allows you to use HTML as your template language and enables you to extend HTML’s syntax to express your application’s components clearly
Can you explain Dependency Injection? and how an object or function can get a hold of its dependencies ?
DI or Dependency Injection is a software design pattern that deals with how code gets hold of its dependencies. In order to retrieve elements of the application which is required to be configured when module gets loaded , the operation “config” uses dependency injection.
These are the ways that object uses to hold of its dependencies
- Typically using the new operator, dependency can be created
- By referring to a global variable, dependency can be looked up
- Dependency can be passed into where it is required
What AngularJS routes do?
Angular js routes enable you to create different URLs for different content in your application. Different URLs for different content enables user to bookmark URLs to specific content. Each such bookmark able URL in Angular.js is called a route
A value in Angular JS is a simple object. It can be a number, string or JavaScript object. Values are typically used as configuration injected into factories, services or controllers. A value should be belonging to an Angular.js module.
Injecting a value into an Angular.js controller function is done by adding a parameter with the same name as the value
What makes AngularJS better?
- Registering Callbacks: There is no need to register callbacks. This makes your code simple and easy to debug.
- Control HTML DOM programmatically: All the application that are created using Angular never have to manipulate the DOM although it can be done if it is required
- Transfer data to and from the UI: Angular.js helps to eliminate almost all of the boiler plate like validating the form, displaying validation errors, returning to an internal model and so on which occurs due to flow of marshalling data
- No initilization code: With angular.js you can bootstrap your app easily using services, which auto-injected into your application in Guice like dependency injection style
What are the steps for the compilation process of HTML happens?
Compilation of HTML process occurs in following ways
- Using the standard browser API, first the HTML is parsed into DOM
- By using the call to the $compile () method, compilation of the DOM is performed. The method traverses the DOM and matches the directives.
- Link the template with scope by calling the linking function returned from the previous step
Can you explain provider?
Provider is used by AngularJS internally to create services, factory etc. during config phase (phase during which AngularJS bootstraps itself). Below mention script can be used to create Math Service that we’ve created earlier. Provider is a special factory method with a method get() which is used to return the value/service/factory.
What is function of $routeProvider?
$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 sam
Can you briefly explain the AngularJS versioning strategy?
In Angular 1 we do not allow intentional breaking changes to appear in versions where only the “patch” number changes. For example between 1.3.12 and 1.3.13 there can be no breaking changes. We do allow breaking changes happen between “minor” number changes. For example between 1.3.15 and 1.4.0 there will be a number of breaking changes. We also allow breaking changes between beta releases of Angular. For example between 1.4.0-beta.4 and 1.4.0-beta.5 there may be breaking changes. We try hard to minimize these kinds of change only to those where there is a strong use case such as a strongly requested feature improvement, a considerable simplification of the code or a measurable performance improvement.
When adding new code to branches of Angular, have a very stringent commit policy:
- Every commit must contain tests and documentation updates alongside the code changes and that all the tests must pass;
- Commit messages must be written in a specific manner that allows us to parse them and extract the changes for release notes.
The Angular code base has a very large set of unit tests (over 4000) and end to end tests, which are pretty comprehensive. This means that a breaking change will require one or more tests to be changed to allow the tests to pass. So when a commit includes tests that are being removed or modified, this is a flag that the code might include a breaking change. When reviewing the commit we can then decide whether there really is a breaking change and if it is appropriate for the branch to which it is being merged. If so, then we require that the commit message contains an appropriate breaking change message.
Additionally, when a commit lands in our master repository it is synced to Google where we test it against over 2000 applications using the test suites of these applications. This allows us to catch regressions quickly before a release. We’ve had a pretty good experience with this setup. Only bugs that affect features not used at Google or without sufficient test coverage, have a chance of making it through.
Lastly, when we are making a release we generate updates to the change log directly from the commits. This generated update contains a highlighted section that contains all the breaking changes that have been extracted from the commits. We can quickly see in the new change log exactly what commits contain breaking changes and so can application developers when they are deciding whether to update to a new version of Angular.
Can you explain the concept of scope hierarchy? How many scope can an application have?
Each angular application consists of one root scope but may have several child scopes. As child controllers and some directives create new child scopes, application can have multiple scopes. When new scopes are formed or created they are added as children of their parent scope. Similar to DOM, they also create a hierarchical structure.
What is the importance of Scope?
- To observer model mutations scopes provide APIs ($watch)
- To propagate any model changes through the system into the view from outside of the Angular realm
- A scope inherits properties from its parent scope, while providing access to shared model properties, scopes can be nested to isolate application components
- Scope provides context against which expressions are evaluated
Can you explain Directive?
A directive in AngularJS is a reusable component. Directives in AngularJS encapsulate all the behavioral properties and functionalities of an element in a semantic way, thereby keeping all of the functionality grouped together. This helps to keep track of changes of one HTML section in one place rather than tracking the changes on a global level in a script. There are 4 different types of directive.
- Elements directive
- Attributes directive
- CSS class names directive
- Comments directive
Can you explain linking Function?
Link combines the directives with a scope and produces a live view. For registering DOM listeners as well as updating the DOM, link function is responsible. After the template is cloned it is executed.
- Pre-linking function: Pre-linking function is executed before the child elements are linked. It is not considered as the safe way for DOM transformation.
- Post linking function: Post linking function is executed after the child elements are linked. It is safe to do DOM transformation by post-linking function
What is the difference between link and compile in AngularJS?
- Compile function: It is used for template DOM Manipulation and collect all of the directives.
- Link function: It is used for registering DOM listeners as well as instance DOM manipulation. It is executed once the template has been cloned.
What is the difference between service and factory method?
Service method is used to create a service whose purpose is to do some defined task.
Factory method is used to define a factory which can later be used to create services as and when required.
Can you explain factory method in AngularJS?
For creating the directive, factory method is used. It is invoked only once, when compiler matches the directive for the first time. By using $injector.invoke the factory method is invoked.
What is Transpiling?
Transpiling is a process of converting code from one language to another. In Angular, Traceur compiler is used for converting TypeScript to JavaScript so that browsers can understand.
Can you define Injector?
An injector is a service locator. It is used to retrieve object instances as defined by provider, instantiate types, invoke methods and load modules. There is a single injector per Angular application; it helps to look up an object instance by its name.
How to make an ajax call using AngularJS?
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;
});
}
What are the styling form that ngModel adds to CSS classes?
ngModel adds these CSS classes to allow styling of form as well as control
- ng- valid
- ng- invalid
- ng-pristine
- ng-dirty
Mention the difference between AngularJS and Backbone.js?
Angular.js combines the functionalities of most of the 3rd party libraries, it supports individual functionalities required to develop HTML5 Apps. While Backbone.js do their jobs individually.
What is *ngFor directive used for?
*ngFor directive is used for Iterating over a list of items and for Generating a new DOM element for each one.
Explain why this project is called AngularJS? Why the namespace is called ng?
Because HTML has Angular brackets and “ng” sounds like “Angular”.
How AngularJS integrates with HTML?
AngularJS being a pure javaScript based library integrates easily with HTML.
Step 1 − Include angularjs javascript libray in the html page
<head>
<script src = “https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js”></script>
</head>
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”>
</body>
Is AngularJS a library, framework, plugin or a browser extension?
AngularJS fits the definition of a framework the best, even though it’s much more lightweight than a typical framework and that’s why many confuse it with a library.
AngularJS is 100% JavaScript, 100% client-side and compatible with both desktop and mobile browsers. So it’s definitely not a plugin or some other native browser extension.
Explain, Is AngularJS a templating system?
At the highest level, Angular does look like just another templating system. But there is one important reason why the Angular templating system is different, that makes it very good fit for application development: bidirectional data binding. The template is compiled in the browser and the compilation step produces a live view. This means you, the developers, don’t need to write code to constantly sync the view with the model and the model with the view as in other templating systems.
Can you explain internationalization?
Internationalization is a way to show locale specific information on a website. For example, display content of a website in English language in United States and in Danish in France.
Can you explain the boot process in AngularJS?
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.