When building dynamic Angular applications, generating components with specific parameters is a common task. Angular CLI's ng generate component command streamlines this process, but understanding how to customize component creation with parameters can significantly enhance your development workflow. This guide explores various methods to create Angular components with parameters, from basic CLI generation to advanced techniques.
Basic Component Generation with Parameters
The Angular CLI provides a straightforward way to generate components with initial parameters. The basic syntax is:
ng generate component component-name [options]
Common parameters include:

--skip-tests: Skip generating spec files--inline-template: Use inline template instead of separate file--inline-style: Use inline styles instead of separate file--style: Specify CSS preprocessor (scss, less, styl)--change-detection: Set change detection strategy
Advanced Parameter Configuration
For more complex scenarios, you can modify the generated component immediately after creation. Here's an example of generating a component with specific input parameters:
ng generate component user-profile --skip-tests --style=scss
This command creates a user-profile component with SCSS styling and skips test file generation.
Programmatic Component Creation
When you need to dynamically create components at runtime, Angular's ComponentFactoryResolver becomes essential. This approach allows you to pass parameters to components programmatically:

// Example of dynamic component creation with parameters
@ViewChild('container', { read: ViewContainerRef }) container: ViewContainerRef;
constructor(private componentFactoryResolver: ComponentFactoryResolver) {}
createComponentWithParams() {
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(YourComponent);
const componentRef = this.container.createComponent(componentFactory);
componentRef.instance.someInput = 'parameter value';
}
Component Input Parameters
Angular components can receive parameters through the @Input() decorator. Here's how to define and use input parameters:
// Component definition
@Component({
selector: 'app-user-card',
template: `<div>{{ userName }}</div>`
})
export class UserCardComponent {
@Input() userName: string;
@Input() userRole: string;
}
// Usage
<app-user-card [userName]="'John Doe'" [userRole]="'Admin'"></app-user-card>
Schema Configuration
When generating components with specific schemas for web components, you can use the --skip-import and --module parameters:
ng generate component custom-element --skip-import --module=app.module.ts
This tells Angular not to import the component into the specified module, which is useful when creating standalone components or web components.
Custom Schematics
For consistent component patterns across your project, consider creating custom schematics. Custom schematics allow you to define default parameters and templates for component generation. This ensures team consistency and reduces repetitive setup work. While more complex to implement initially, custom schematics pay dividends in larger projects where multiple developers follow the same patterns.
Best Practices
When creating components with parameters, follow these best practices:
- Use descriptive parameter names that clearly indicate their purpose
- Provide default values for optional parameters
- Include type annotations for all inputs
- Create interfaces for complex parameter objects
- Consider using reactive forms for components with multiple related inputs
Performance Considerations
When creating components dynamically, be mindful of performance implications. Angular's change detection can be intensive with many dynamic components. Use OnPush change detection strategy where appropriate, and consider component caching for frequently created components with similar parameters.