What is AngularJS?
- A
A JavaScript framework for building dynamic web applications
- B
A CSS framework for styling web pages
- C
A server-side programming language
- D
A database management system
Master AngularJS concepts with 120+ curated MCQs covering directives, scopes, services, dependency injection, routing, and more. Perfect for exams, interviews, and placement preparation.
What is AngularJS?
A JavaScript framework for building dynamic web applications
A CSS framework for styling web pages
A server-side programming language
A database management system
Who developed AngularJS?
Microsoft
Amazon
Which directive is used to bootstrap an AngularJS application?
ng-boot
ng-app
ng-init
ng-model
AngularJS is based on which architectural pattern?
MVC (Model-View-Controller)
MVVM (Model-View-ViewModel)
MVP (Model-View-Presenter)
Microservices
Which of the following is true about AngularJS?
It is a front-end framework
It supports two-way data binding
It uses dependency injection
All of the above
What is the purpose of the 'ng-model' directive?
To bind HTML elements to application data
To initialize an AngularJS app
To repeat an HTML element for each item in a collection
To conditionally show or hide elements
Which directive is used to repeat an element for each item in an array?
ng-repeat
ng-foreach
ng-loop
ng-iterate
What does the 'ng-if' directive do?
It removes or recreates an element based on a condition
It hides or shows an element without removing it
It binds a model to an input field
It initializes a scope variable
Which directive is used to hide an element if a condition is true?
ng-show
ng-hide
ng-if
ng-visible
What is the difference between ng-show and ng-if?
ng-show hides the element using CSS, ng-if removes the element from DOM
ng-show removes the element, ng-if hides it
Both are identical
ng-show is used for arrays, ng-if for objects
Which directive is used to bind HTML content to a model property?
ng-bind
ng-bind-html
ng-html
ng-model
Which directive is used to execute an expression when a user clicks an element?
ng-click
ng-change
ng-submit
ng-mouseover
How many $rootScope can an AngularJS application have?
Two
Infinity
One
Zero
What is the relationship between $rootScope and $scope?
$rootScope is the parent of all $scopes
$scope is the parent of $rootScope
They are unrelated
$rootScope is a child of $scope
How do you create a new child scope in AngularJS?
Using the $new() method
Using the $create() method
Using the $scope() method
Automatically when a controller is created
What is scope inheritance in AngularJS?
Child scopes inherit properties from parent scopes
Parent scopes inherit from child scopes
Scopes do not inherit
Only $rootScope inherits
Which method is used to propagate changes from a child scope to parent?
$emit
$broadcast
$on
$watch
What is the purpose of $apply in AngularJS?
To manually trigger a digest cycle
To create a new scope
To destroy a scope
To bind a model
What type of data binding does AngularJS support?
One-way binding
Two-way binding
Both one-way and two-way
No data binding
Which directive enables two-way data binding?
ng-bind
ng-model
ng-value
ng-data
How do you bind a model property to an HTML element in AngularJS?
Using double curly braces {{ }}
Using the ng-bind directive
Using the ng-model directive
All of the above
What is the difference between ng-bind and interpolation {{ }}?
ng-bind prevents flickering, interpolation may show raw expression briefly
Interpolation is faster
ng-bind is only for attributes
There is no difference
What is one-way binding in AngularJS?
Data flows from model to view only
Data flows from view to model only
Data flows both ways
Data does not flow
Which of the following is a disadvantage of two-way binding?
Can cause performance issues with large datasets
It is not supported in AngularJS
It requires extra code
It only works with strings
What is Dependency Injection in AngularJS?
A design pattern where objects are passed their dependencies rather than creating them internally
A method to inject HTML into the DOM
A way to create directives
A technique for optimizing performance
How is dependency injection implemented in AngularJS?
Using injectable services and factories
Using global variables
Using JavaScript prototypes
Using CSS classes
Which of the following can be injected as a dependency in AngularJS?
Factory
Value
Constant
All of the above
What is the purpose of the $injector in AngularJS?
It is used to retrieve and instantiate injectable objects
It is used to inject HTML
It is used to create directives
It is used to handle events
Which service is used to share data across controllers?
$rootScope
$scope
$http
$location
How do you define a service in AngularJS?
Using module.service() or module.factory()
Using module.directive()
Using module.controller()
Using module.config()
What is the purpose of filters in AngularJS?
To format data for display
To filter arrays based on conditions
To sort data
All of the above
Which filter is used to convert a string to lowercase?
lowercase
lower
tolower
case
Which filter is used to format dates?
date
time
datetime
format
How do you apply a filter in an AngularJS template?
Using the pipe character |
Using the filter method
Using the ng-filter directive
Using the filter attribute
Which filter is used to limit the number of items in an array?
limitTo
slice
take
first
Can you chain multiple filters in AngularJS?
Yes, using multiple pipe characters
No, only one filter per expression
Yes, using commas
No, filters cannot be combined
Which module is used for routing in AngularJS?
ngRoute
ngRouter
ngRouting
RouteModule
What is the $routeProvider used for?
To configure routes in AngularJS
To provide route parameters
To handle route events
All of the above
Which directive is used to render the view for a route?
ng-view
ng-route
ng-template
ng-partial
What is deep linking in AngularJS?
Encoding the application state in the URL to allow bookmarking
Linking to external websites
Using HTML5 history API
Linking to elements within a page
Which method is used to navigate to a different route programmatically?
$location.path()
$route.go()
$router.navigate()
window.location
What is the role of $routeParams?
To access route parameters from the URL
To configure routes
To define route events
To render the view
Which directive is used to create a form in AngularJS?
ng-form
form
ng-form
Both A and B
What is the purpose of the 'novalidate' attribute on a form?
To disable browser validation
To enable AngularJS validation
To reset the form
To submit the form
Which property of a form controller indicates whether the form is valid?
$valid
$invalid
$pristine
$dirty
What does $dirty mean on a form control?
The user has interacted with the control
The control is invalid
The control has not been touched
The control is disabled
Which directive is used for AngularJS validation?
ng-required
ng-minlength
ng-pattern
All of the above
How do you display error messages for a form control?
Using ng-show with formName.fieldName.$error
Using ng-messages
Both A and B
Neither
What is the difference between a service and a factory in AngularJS?
A service is a constructor function, a factory is a function that returns an object
A factory is a constructor, a service returns an object
There is no difference
Service is synchronous, factory is asynchronous
What is the $http service used for?
To make AJAX requests
To handle HTTP routing
To parse HTML
To manage cookies
Which service is used to interact with the browser's location?
$location
$window
$document
$browser
What is the purpose of the $timeout service?
To execute a function after a delay
To cancel a timeout
To clear intervals
All of the above
How do you create a constant in AngularJS?
Using module.constant()
Using module.value()
Using module.factory()
Using module.provider()
What is a provider in AngularJS?
A configurable service
A type of directive
A filter
A controller
What is the role of a controller in AngularJS?
To control the data and logic for a view
To define HTML templates
To configure routing
To create services
How do you define a controller in AngularJS?
Using module.controller()
Using module.directive()
Using module.service()
Using module.filter()
What is the purpose of 'controller as' syntax?
To alias the controller instance in the view
To inject dependencies
To define controller methods
To handle events
Can a controller be used in multiple views?
Yes, it can be reused
No, each view needs its own controller
Only if using the same module
Only if using $rootScope
What is the $scope object in a controller?
It is the context for the view data
It is the global object
It is a service
It is a directive
How do you share data between two controllers?
Using a service or factory
Using $rootScope
Using events
All of the above
What is a module in AngularJS?
A container for controllers, services, directives, etc.
A separate HTML file
A CSS stylesheet
A third-party library
How do you create a module in AngularJS?
Using angular.module()
Using module.create()
Using ng-app directive
Using $module
How do you inject a module as a dependency?
Passing it as an array argument to angular.module()
Using the require attribute
Using the import statement
It is automatic
What is the purpose of module.config()?
To configure providers and services
To define controllers
To register directives
To set up routing
What is the difference between module.run() and module.config()?
run() is executed after config() and can use services
config() is executed after run()
Both are executed at the same time
run() is for configuration, config() for initialization
Can you have multiple modules in one AngularJS application?
Yes, by using dependency injection
No, only one module per app
Yes, but they cannot interact
No, modules are global
How do you create a custom directive in AngularJS?
Using module.directive()
Using module.controller()
Using module.service()
Using module.filter()
What is the 'restrict' property in a directive definition?
It defines how the directive can be used: element, attribute, class, or comment
It restricts the directive to only work on certain elements
It specifies the scope of the directive
It defines the template URL
What is the 'scope' property in a directive?
It defines whether the directive has its own scope or shares parent scope
It defines the template
It defines the controller
It defines the link function
What is the link function in a directive?
It manipulates the DOM and handles events
It defines the template
It configures the scope
It injects dependencies
What is the difference between '=' and '@' in the scope binding of a directive?
'=' is two-way binding, '@' is one-way binding of a string attribute
'@' is two-way binding, '=' is one-way
Both are the same
'=' is for objects, '@' for strings
Which directive is used to transclude content?
transclude: true
ng-transclude
Both A and B
None
How do you handle a click event in AngularJS?
Using ng-click directive
Using onclick attribute
Using addEventListener
Using ng-mouseover
What is the ng-change directive used for?
To execute an expression when the model changes
To execute on click
To execute on mouseover
To execute on keyup
Which directive is used to prevent default behavior of an event?
ng-prevent
ng-default
ng-stop
There is no built-in directive, you can use $event.preventDefault()
How do you pass the $event object to a function in AngularJS?
By including $event in the function call
It is automatically passed
By using event parameter
Not possible
What is the purpose of the ng-submit directive?
To handle form submission
To submit the form via AJAX
To reset the form
To validate the form
Which directive is used to handle keyboard events like keyup?
ng-keyup
ng-keypress
ng-keydown
All of the above
Which service is used to make HTTP requests in AngularJS?
$http
$ajax
$request
$fetch
What is the $http.get() method used for?
To send a GET request to a server
To send a POST request
To update data
To delete data
How do you handle errors in $http?
Using .catch() method
Using .error() callback
Using .fail() method
Using try-catch
What is the $http.defaults used for?
To configure default headers and settings for all HTTP requests
To set default timeout
To configure interceptors
All of the above
How do you set a custom header in $http?
Using the headers property in the config object
Using $http.headers
Using $http.setHeader()
Not possible
What is the purpose of $http interceptors?
To globally handle requests and responses
To cache responses
To transform data
To handle authentication
Which module is used for internationalization in AngularJS?
angular-i18n
ngI18n
i18n
angular-translate
What is the $locale service used for?
To get locale-specific information like date, number formats
To set the language
To translate strings
To detect browser language
How can you change the language in AngularJS?
By loading the appropriate locale script
Using $locale.change()
Using $rootScope.language
It is not possible
Which filter is affected by locale settings?
date
currency
number
All of the above
What is the purpose of the ngPluralize directive?
To handle pluralization of strings based on locale
To pluralize numbers
To format numbers
To translate text
Can you use AngularJS i18n with custom translations?
Yes, by using filters or directives
No, only built-in locale
Yes, but only with server-side support
No, it's not supported
What is the recommended way to watch models for performance?
Use $watch with deep equality only when necessary
Use $watchCollection for arrays
Avoid unnecessary watches
All of the above
What is the purpose of one-time binding in AngularJS (::) )?
To bind once and not update, improving performance
To bind in both directions
To bind only on initialization
To disable binding
How can you reduce the number of digest cycles?
Use $applyAsync to batch updates
Use ng-if instead of ng-show
Use one-time binding
All of the above
What is the best practice for organizing AngularJS code?
Use the 'Controller As' syntax
Keep controllers thin and services fat
Use modules to organize components
All of the above
What is the purpose of $destroy event?
To clean up resources when a scope is destroyed
To destroy the application
To remove all watchers
To reset the scope
How should you handle large ng-repeat lists?
Use limitTo filter or pagination
Use track by to avoid re-rendering
Both A and B
None
Which testing framework is commonly used with AngularJS?
Jasmine
Mocha
Jest
All of the above
What is AngularJS's $httpBackend used for in testing?
To mock HTTP requests
To make real HTTP calls
To configure headers
To intercept responses
How do you inject dependencies in AngularJS unit tests?
Using angular.mock.inject()
Using $injector
Using new keyword
Using require
What is the purpose of $controller in tests?
To instantiate a controller with mocked scope
To test directive controllers
Both A and B
None
What is the angular.mock.module() used for?
To load modules in tests
To configure modules
To mock modules
All of the above
How do you test directives in AngularJS?
By compiling the directive and testing the compiled element
By using $compile service
Both A and B
None
What is the main difference between AngularJS and Angular (2+) ?
AngularJS uses JavaScript, Angular uses TypeScript
AngularJS is based on MVC, Angular uses component-based architecture
Angular has better performance
All of the above
Which of these is a feature of AngularJS?
Two-way data binding
Directives
Dependency Injection
All of the above
What is the primary advantage of AngularJS over jQuery?
Two-way data binding
Simpler DOM manipulation
Better browser support
Lighter weight
Which framework is more suitable for large-scale applications?
AngularJS
React
Angular
Vue
Is AngularJS still widely used today?
Yes, for legacy applications
No, it is deprecated
It is used only for new projects
It is the most popular front-end framework
What is the AngularJS equivalent of a React component?
Directive
Controller
Service
Filter
What is the purpose of the ng-cloak directive?
To prevent the browser from displaying the raw AngularJS template during load
To cloak the application from users
To hide elements until the page is fully loaded
To encrypt the data
What is the AngularJS digest cycle?
The process of watching for changes and updating the view
The compilation of templates
The dependency injection process
The routing process
How do you sanitize HTML in AngularJS?
Using $sanitize service
Using ng-bind-html
Using $sce.trustAsHtml
All of the above
What is the purpose of $q in AngularJS?
To handle promises and asynchronous operations
To query the DOM
To create queries
To handle JSON
What is the 'controllerAs' syntax used for?
To assign an alias to the controller in the view
To define controller methods
To inject services
To handle events
How do you handle form submissions in AngularJS?
Using ng-submit directive
Using $http to send data
Both A and B
Using jQuery
What is the purpose of the ng-switch directive?
To conditionally display elements based on an expression
To switch between views
To toggle visibility
To handle events
Which directive is used to include HTML templates in AngularJS?
ng-include
ng-template
ng-html
ng-partial
What is the purpose of $rootScope?
It is the global scope available across all controllers
It is the scope for a specific controller
It is a service
It is a directive
How do you debug an AngularJS application?
Using Batarang extension
Using console.log
Using $log service
All of the above
What is the purpose of the ng-options directive?
To create dropdown options from an array
To iterate over a collection
To bind to a select element
All of the above
What is the difference between ng-options and ng-repeat for select?
ng-options is more efficient for large datasets and supports object binding
ng-repeat is simpler but less efficient
Both are equally efficient
ng-options is deprecated