Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: cannot .replace() a component that has an abstract base class #8201

Open
Eugeny opened this issue Feb 12, 2024 · 3 comments
Open

Bug: cannot .replace() a component that has an abstract base class #8201

Eugeny opened this issue Feb 12, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@Eugeny
Copy link

Eugeny commented Feb 12, 2024

ng-mocks is checking the decorators and will fail if there's both @Component and @Injectable present. Instead, it should ignore @Injectable if there's @Component or @Directive present.

@Injectable is required on base component classes to avoid the Class is using Angular features error when inheriting, for example:

@Injectable()
abstract class Base {
	ngOnInit () {} 
}

@Component({...})
class Component extends Base {}
@Eugeny Eugeny added the bug Something isn't working label Feb 12, 2024
@Dji75
Copy link
Contributor

Dji75 commented Jun 13, 2024

Why do you need Base to be Injectable as you can't inject it directly ? 🤔

I have a similar architecture, so I can purpose another way if you can adapt your code:

@Component({
  selector: 'app-base',
  template: '',
  standalone: true,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export abstract class Base {

@Eugeny
Copy link
Author

Eugeny commented Jun 13, 2024

It's a base class for both components and directives

@Dji75
Copy link
Contributor

Dji75 commented Jun 13, 2024

What about an abstract directive then ?

@Directive({
  standalone: true,
})
export abstract class Base {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants