Software⏱️ 2 min read📅 2026-05-31

How to Fix: Angular @ViewChild() error: Expected 2 arguments, but got 1

Learn how to fix: Angular @ViewChild() error: Expected 2 arguments, but got 1.

Quick Answer: Try checking your system settings or restarting.

When trying to use ViewChild in Angular, you may encounter the error 'An argument for 'opts' was not provided.' This error occurs when the ViewChild decorator is used without providing any options.

🛑 Root Causes of the Error

  • Incorrect usage of ViewChild decorator.

✅ Best Solutions to Fix It

Method 1: Pass Options to ViewChild Decorator

  1. Step 1: Add the options object to the ViewChild decorator.

Method 2: Use Optional Chaining (Angular 9+)

  1. Step 1: Update your Angular version to 9 or higher.

🎯 Final Words

By following these methods, you should be able to resolve the error and successfully use ViewChild in your Angular application.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions