Sub topic 2
Installing the extension and meeting its requirements
This chapter assumes you can build and serve an Angular app with the Angular CLI. It also assumes you have used the Elements and Console panels in browser developer tools. By the end, you will have Angular DevTools installed and will know why it sometimes reports that it cannot see your app.
What you need
Angular DevTools is a browser extension. It adds an Angular tab to the browser's developer tools. The extension only works when these conditions hold:
| Requirement | Detail |
|---|---|
| Browser | Chrome or Firefox. Chromium-based browsers such as Edge can usually install the Chrome version. |
| Angular version | Angular 12 or later, with the Ivy renderer (the default since Angular 9). |
| Build mode | Development mode. Production builds are not supported. |
| Page | The app must be loaded in a normal tab, with browser developer tools open. |
The build mode is the requirement that causes the most trouble. In a production build, Angular removes the debugging hooks that the extension reads. The extension can therefore see nothing useful.
Installing the extension
- Open the extension store for your browser: the Chrome Web Store or Firefox Add-ons.
- Search for "Angular DevTools" and check that the publisher is the Angular team.
- Add the extension to your browser and confirm the permission prompt.
- Reload any Angular tabs that were open before you installed it.
Serving the app in development mode
ng serve builds in development mode by default, so no extra setup is needed for local work.
ng serveIf you serve a built copy instead, build with the development configuration:
ng build --configuration developmentThen serve the output folder with any static file server. A default ng build uses the production configuration, and DevTools will not work with that output.
Confirming that DevTools detects the app
Open the app in the browser, then open developer tools (F12, or Ctrl+Shift+I, or Cmd+Option+I on macOS). An Angular tab should appear next to Elements and Console. When the page is a supported Angular app, the tab shows the component explorer and profiler.
You can check the same conditions yourself from the Console. This snippet reads the version that Angular writes onto the root element, and it checks for the development-mode ng global:
// Version stamped on the root element by Angular
const root = document.querySelector('[ng-version]');
console.log('Angular version:', root?.getAttribute('ng-version'));
// The ng global exists only in development mode
console.log('Debug utilities available:', typeof ng !== 'undefined');If the version prints but typeof ng is 'undefined', the app is almost certainly a production build.
Common problems
- No Angular tab. The extension is not enabled, or the tab was open before installation. Reload the page. In some browsers you must also close and reopen developer tools.
- A message says the app was built in production mode. Rebuild as described above. Check that no
optimizationor--prodstyle flags are in use. - A message says the Angular version is unsupported. The app uses a version older than 12, or it does not run on Ivy. Upgrade Angular or use the console utilities on a supported version.
- The app is inside an iframe or on another origin. Select the correct frame in the developer tools frame selector. The extension inspects one page context at a time.
Exercise
You open a deployed site built with a default ng build. The Console prints an ng-version value, but the Angular tab reports that it cannot inspect the app, and typeof ng is 'undefined'. What is the cause, and how do you get a working session?
Show answer
The site is a production build. Angular strips the debugging hooks in that mode, so DevTools and the ng global are unavailable even though the version attribute remains. Reproduce the issue locally by running ng serve, or by building with ng build --configuration development, and open that version with DevTools.