Create New Post

AngularJS MCQ with answer

  1. What is AngularJS?

    • A. A server-side scripting language
    • B. A JavaScript framework for building web applications
    • C. A database management system
    • D. A text editor

    Answer: B. A JavaScript framework for building web applications

  2. Who developed AngularJS?

    • A. Google
    • B. Microsoft
    • C. Facebook
    • D. Twitter

    Answer: A. Google

  3. What does the "ng" in AngularJS stand for?

    • A. Next Generation
    • B. New Growth
    • C. Angular
    • D. No Good

    Answer: C. Angular

  4. Which directive is used for two-way data binding in AngularJS?

    • A. ng-bind
    • B. ng-model
    • C. ng-repeat
    • D. ng-change

    Answer: B. ng-model

  5. What is the purpose of ng-app directive in AngularJS?

    • A. It defines an AngularJS module
    • B. It initializes a new AngularJS application
    • C. It binds a model to an HTML element
    • D. It defines a new controller

    Answer: B. It initializes a new AngularJS application

  6. What is an AngularJS module?

    • A. A JavaScript function
    • B. A collection of JavaScript functions
    • C. A reusable piece of code
    • D. A container for the different parts of an application

    Answer: D. A container for the different parts of an application

  7. Which directive is used to repeat a set of HTML elements in AngularJS?

    • A. ng-repeat
    • B. ng-if
    • C. ng-show
    • D. ng-switch

    Answer: A. ng-repeat

  8. What is the purpose of ng-controller directive in AngularJS?

    • A. It defines a new controller
    • B. It initializes a new AngularJS application
    • C. It binds a model to an HTML element
    • D. It defines an AngularJS module

    Answer: A. It defines a new controller

  9. What does the "scope" in AngularJS refer to?

    • A. The visible area of a web page
    • B. A JavaScript object that refers to the application model
    • C. A part of the HTML document
    • D. A type of directive

    Answer: B. A JavaScript object that refers to the application model

  10. Which service is used for making HTTP requests in AngularJS?

    • A. $http
    • B. $ajax
    • C. $request
    • D. $xhr

    Answer: A. $http

  11. In AngularJS, what is the purpose of the "ng-show" directive?

    • A. To hide an HTML element
    • B. To show an HTML element
    • C. To conditionally display an HTML element
    • D. To create animations

    Answer: C. To conditionally display an HTML element

  12. What is the purpose of the "ng-hide" directive in AngularJS?

    • A. To hide an HTML element
    • B. To show an HTML element
    • C. To conditionally hide an HTML element
    • D. To create animations

    Answer: C. To conditionally hide an HTML element

  13. What is the purpose of ng-click directive in AngularJS?

    • A. To conditionally hide an HTML element
    • B. To handle a click event on an HTML element
    • C. To create animations
    • D. To show an HTML element

    Answer: B. To handle a click event on an HTML element

  14. Which of the following is true about services in AngularJS?

    • A. Services are used to define controllers
    • B. Services are not reusable across different parts of an application
    • C. Services are singletons and are used for business logic, data sharing, and communication
    • D. Services can only be used in controllers, not in directives

    Answer: C. Services are singletons and are used for business logic, data sharing, and communication

  15. What is the purpose of ng-submit directive in AngularJS?

    • A. To conditionally hide an HTML element
    • B. To handle a form submission
    • C. To create animations
    • D. To show an HTML element

    Answer: B. To handle a form submission

  16. In AngularJS, how can you define a route for a view using ngRoute?

    • A. By using the ng-route attribute on the HTML element
    • B. By using the ng-route directive in the AngularJS module configuration
    • C. By using the $routeProvider service in the AngularJS module configuration
    • D. By including a route.js file in the HTML

    Answer: C. By using the $routeProvider service in the AngularJS module configuration

  17. What is dependency injection in AngularJS?

    • A. A way to include external libraries in AngularJS applications
    • B. A design pattern for managing dependencies and making components more modular
    • C. A method for handling AJAX requests in AngularJS
    • D. A way to create new instances of controllers

    Answer: B. A design pattern for managing dependencies and making components more modular

  18. Which directive is used to include external HTML files in AngularJS?

    • A. ng-include
    • B. ng-external
    • C. ng-import
    • D. ng-attach

    Answer: A. ng-include

  19. What does the "ng-disabled" directive do in AngularJS?

    • A. It disables all HTML elements on the page
    • B. It disables a specific HTML element
    • C. It conditionally disables an HTML element based on an expression
    • D. It enables all HTML elements on the page

    Answer: C. It conditionally disables an HTML element based on an expression

  20. Which directive is used for input validation in AngularJS?

    • A. ng-validate
    • B. ng-check
    • C. ng-model
    • D. ng-required

    Answer: D. ng-required

  21. What is the purpose of AngularJS filters?

    • A. To format and transform data displayed in the view
    • B. To handle user authentication
    • C. To define routes in the application
    • D. To create animations

    Answer: A. To format and transform data displayed in the view

  22. Which AngularJS service is used to handle promises?

    • A. $http
    • B. $q
    • C. $promise
    • D. $deferred

    Answer: B. $q

  23. What does ng-show/ng-hide do in AngularJS?

    • A. It changes the visibility of an HTML element based on a condition
    • B. It animates the showing/hiding of an HTML element
    • C. It toggles the display of an HTML element
    • D. It creates a new HTML element based on a condition

    Answer: A. It changes the visibility of an HTML element based on a condition

  24. Which directive is used to handle keyboard events in AngularJS?

    • A. ng-keyboard
    • B. ng-event
    • C. ng-keypress
    • D. ng-input

    Answer: C. ng-keypress

  25. What is the purpose of ng-options in AngularJS?

    • A. It defines options for a select dropdown
    • B. It defines options for ng-repeat
    • C. It sets options for ng-model
    • D. It creates options for ng-bind

    Answer: A. It defines options for a select dropdown

  26. How does AngularJS handle forms and form validation?

    • A. Forms are not supported in AngularJS
    • B. AngularJS uses the ng-form directive for form validation
    • C. AngularJS automatically tracks and validates form data using the ng-model directive
    • D. Form validation is handled using a separate AngularJS module

    Answer: C. AngularJS automatically tracks and validates form data using the ng-model directive

  27. What is the purpose of ng-cloak in AngularJS?

    • A. To hide an HTML element
    • B. To prevent displaying uncompiled AngularJS expressions
    • C. To create animations
    • D. To conditionally display an HTML element

    Answer: B. To prevent displaying uncompiled AngularJS expressions

  28. Which directive is used for routing in AngularJS applications?

    • A. ng-route
    • B. ng-router
    • C. ng-routing
    • D. ng-navigation

    Answer: A. ng-route

  29. What is the purpose of $rootScope in AngularJS?

    • A. To define global variables
    • B. To create a new root scope for each controller
    • C. To define global functions
    • D. To broadcast events to all child scopes

    Answer: A. To define global variables

  30. What does the "digest cycle" in AngularJS refer to?

    • A. The process of updating the view when the model changes
    • B. The process of initializing AngularJS applications
    • C. The process of compiling HTML templates
    • D. The process of handling HTTP requests

    Answer: A. The process of updating the view when the model changes

  31. How can you create a custom directive in AngularJS?

    • A. By using the ng-custom directive
    • B. By defining a new controller
    • C. By using the ng-directive directive
    • D. By using the directive method in an AngularJS module

    Answer: D. By using the directive method in an AngularJS module

  32. What is the purpose of ng-animate in AngularJS?

    • A. To define animations in AngularJS applications
    • B. To disable animations in AngularJS applications
    • C. To conditionally animate HTML elements
    • D. To animate ng-repeat elements

    Answer: A. To define animations in AngularJS applications

  33. How does AngularJS support testing?

    • A. AngularJS does not provide testing support
    • B. By using the Jasmine testing framework
    • C. By using the Protractor testing framework
    • D. By providing the ng-test directive

    Answer: B. By using the Jasmine testing framework

  34. What is the purpose of ng-init in AngularJS?

    • A. To initialize a new AngularJS module
    • B. To define initial values for variables in the controller
    • C. To create a new instance of a controller
    • D. To handle form initialization

    Answer: B. To define initial values for variables in the controller

  35. What does the "track by" clause in ng-repeat do in AngularJS?

    • A. It disables tracking of ng-repeat items
    • B. It defines a unique key for tracking the identity of ng-repeat items
    • C. It tracks the iteration count of ng-repeat
    • D. It is not a valid clause in ng-repeat

    Answer: B. It defines a unique key for tracking the identity of ng-repeat items

  36. What is the purpose of $location service in AngularJS?

    • A. To handle form submissions
    • B. To manage the application's URL
    • C. To make HTTP requests
    • D. To create animations

    Answer: B. To manage the application's URL

  37. Which directive is used to bind HTML content in AngularJS?

    • A. ng-content
    • B. ng-html
    • C. ng-bind-html
    • D. ng-html-content

    Answer: C. ng-bind-html

  38. How can you prevent the default action of an event in AngularJS?

    • A. By using ng-default-action directive
    • B. By using ng-stop-propagation directive
    • C. By using ng-prevent-default directive
    • D. By calling event.preventDefault() in the event handler

    Answer: C. By using ng-prevent-default directive

  39. What is ng-href used for in AngularJS?

    • A. To define a hyperlink in AngularJS
    • B. To conditionally set the href attribute of an HTML element
    • C. To handle hyperlink clicks
    • D. To create animations

    Answer: B. To conditionally set the href attribute of an HTML element

  40. How can you dynamically load a template in AngularJS?

    • A. By using ng-template directive
    • B. By using ng-dynamic directive
    • C. By using ng-load-template directive
    • D. By using ng-include directive

    Answer: D. By using ng-include directive

  41. What is the purpose of ng-class in AngularJS?

    • A. To conditionally apply CSS classes to HTML elements
    • B. To define a new CSS class
    • C. To create animations
    • D. To handle form submissions

    Answer: A. To conditionally apply CSS classes to HTML elements

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

17039