Repository navigation
Closed
Labels
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: coreIssues related to the framework runtimebugcore: host directivesstate: has PR
Milestone
Description
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
It seems like an @Input() that was renamed via @Input("myCustomName") can't be added to the host directives inputs array.
I was just following the official Introducing the Directive Composition API in Angular v15 video on YouTube.
Here's an example using the CdkContextMenuTrigger directive:
import { CdkContextMenuTrigger } from '@angular/cdk/menu';
import { Directive } from '@angular/core';
@Directive({
standalone: true,
selector: '[myTriggerFor]',
hostDirectives: [
{
directive: CdkContextMenuTrigger,
inputs: [
'cdkContextMenuTriggerFor: myTriggerFor',
'cdkContextMenuPosition',
'cdkContextMenuTriggerData',
],
outputs: ['cdkContextMenuOpened', 'cdkContextMenuClosed'],
},
],
})
export class MyMenuTriggerDirective {}And a simplified version of using it:
import { Component } from '@angular/core';
import { MyMenuTriggerDirective } from './my-menu.directive';
@Component({
selector: 'app-root',
template: `
<button [myTriggerFor]="name">trigger</button>
<ng-template #name></ng-template>
`,
standalone: true,
imports: [MyMenuTriggerDirective],
})
export class AppComponent {}Doing so result in the errors below. Or is this working as intended?
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
ERROR Error: NG0312: Cannot alias output cdkContextMenuOpened of host directive CdkContextMenuTrigger to cdkContextMenuOpened, because it already has a different output with the same public name.
at validateMappings (core.mjs:12831:23)
at validateHostDirective (core.mjs:12812:5)
at Object.findHostDirectiveDefs (core.mjs:12727:17)
at findDirectiveDefMatches (core.mjs:11190:46)
at resolveDirectives (core.mjs:10953:29)
at elementStartFirstCreatePass (core.mjs:13659:27)
at Module.ɵɵelementStart (core.mjs:13699:9)
at AppComponent_Template (app.component.ts:7:5)
at executeTemplate (core.mjs:10534:9)
at renderView (core.mjs:10356:13)
ERROR Error: Uncaught (in promise): Error: NG0312: Cannot alias output cdkContextMenuOpened of host directive CdkContextMenuTrigger to cdkContextMenuOpened, because it already has a different output with the same public name.
Error: NG0312: Cannot alias output cdkContextMenuOpened of host directive CdkContextMenuTrigger to cdkContextMenuOpened, because it already has a different output with the same public name.
at validateMappings (core.mjs:12831:23)
at validateHostDirective (core.mjs:12812:5)
at Object.findHostDirectiveDefs (core.mjs:12727:17)
at findDirectiveDefMatches (core.mjs:11190:46)
at resolveDirectives (core.mjs:10953:29)
at elementStartFirstCreatePass (core.mjs:13659:27)
at Module.ɵɵelementStart (core.mjs:13699:9)
at AppComponent_Template (app.component.ts:7:5)
at executeTemplate (core.mjs:10534:9)
at renderView (core.mjs:10356:13)
at resolvePromise (zone.js:1214:31)
at zone.js:1285:17
at _ZoneDelegate.invokeTask (zone.js:409:31)
at core.mjs:23999:55
at AsyncStackTaggingZoneSpec.onInvokeTask (core.mjs:23999:36)
at _ZoneDelegate.invokeTask (zone.js:408:60)
at Object.onInvokeTask (core.mjs:24300:33)
at _ZoneDelegate.invokeTask (zone.js:408:60)
at Zone.runTask (zone.js:178:47)
at drainMicroTaskQueue (zone.js:588:35)
Please provide the environment you discovered this bug in (run ng version)
Angular CLI: 15.1.4
Node: 18.12.1
Package Manager: npm 8.19.2
OS: linux x64
Angular: 15.1.3
... animations, cdk, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1501.4
@angular-devkit/build-angular 15.1.4
@angular-devkit/core 15.1.4
@angular-devkit/schematics 15.1.4
@angular/cli 15.1.4
@schematics/angular 15.1.4
rxjs 7.8.0
typescript 4.9.5
Anything else?
No response
Reacted by Felix Baltruschat, Nils Ziermann, Vladyslav Nyzhashchyy, Manuel Schulte and skazaz-utila
Metadata
Metadata
Assignees
Labels
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: coreIssues related to the framework runtimebugcore: host directivesstate: has PR
Activity
crisbeto commentedon Feb 4, 2023
This does seem like a bug in the validation. The problem is that the
cdkContextMenuPositionisn't actually an input onCdkContextMenuTrigger, but rather a property calledmenuPositionthat is inherited fromCdkMenuTriggerBaseand exposed through theinputsarray. Usually the workaround would be to exposemenuPosition, but that won't work in this case, because it isn't actually marked as an input.TomTomB commentedon Feb 4, 2023
Mhm, okay. So that's a implementation issue on the CDK side? I think these kinds of inputs / outputs should also be supported by host directives. Even though, this style is not recommended by the Angular Styleguide, it's part of the framework.
Apart from that there's also a kind of weird behavior when exposing the
@Input('cdkContextMenuDisabled')via host directive.That also results in error NG0312. Renaming it fixes the issue.
crisbeto commentedon Feb 4, 2023
Nah, this is a problem with how the validation is implemented in the Framework's runtime. It should be a supported case.
fix(core): host directives incorrectly validating aliased bindings (#…
angular-automatic-lock-bot commentedon Jun 19, 2023
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.