Topic: Angular 18 Dropdown in Navbar is initially expanded
sistemiUCSC
priority
asked 3 weeks ago
*_Expected behavior_*drop down open and close should work and by default the dropdown should be close which is right here in open state.
*Actual behavior*dropdown is not working and by default dropdown state is open.
Resources (screenshots, code snippets etc.)
<div class="btn-body">
<uf *ngIf="iconLeft" icon="{{ iconLeft.iconName }}" class="uf left" [ngClass]="{'m-0': onlyIconLeft}"
[loadSvgFile]="iconLeft.loadSvgFile" [showCircle]="iconLeft.showCircle" [color]="iconLeft.color"></uf>
<div class="text" *ngIf="buttonDropDown.label">
{{ buttonDropDown.label | translate }}
<ng-container *ngIf="buttonDropDown.label2">
<br />
{{ buttonDropDown.label2 | translate}}
</ng-container>
</div>
<uf *ngIf="iconRight" icon="{{ iconRight.iconName }}" class="uf right" [ngClass]="{'m-0': onlyIconRight}"
[loadSvgFile]="iconRight.loadSvgFile" [showCircle]="iconRight.showCircle" [color]="iconRight.color"></uf>
</div>
{{ buttonDropDown.counterValue }}
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Status
Answered
Specification of the issue
- ForumUser: Priority
- Premium support: Yes
- Technology: MDB Angular
- MDB Version: MDB5 7.1.0
- Device: no
- Browser: chroome
- OS: windows
- Provided sample code: No
- Provided link: No
Arkadiusz Idzikowski staff commented 3 weeks ago
Is it a full HTML code that you wanted to attach? I could not find any dropdown directive usage in this code.
Did you add
MdbDropdownModule
import?sistemiUCSC priority commented 2 weeks ago
if I add it it gives me this error: "Cannot read properties of undefined (reading 'menuPositionClassChanged') "
Arkadiusz Idzikowski staff commented 2 weeks ago
Could you please edit your first post and provide a full HTML/TS code that you use for the dropdown? We won't be able to help without some additional information about your code and configuration.
sistemiUCSC priority commented 2 weeks ago
constructor( private dropdownService: NgxUnicattDropdownService, private ele: ElementRef ) { }
ngOnInit(): void { this.dropdownSub = this.dropdownService.dropdownState$ .subscribe((openedId: string | null) => { // Se l'id non corrisponde a questo dropdown, chiudi questo dropdown if (openedId !== this.uuid) { this.hideDrop(); } }); }
ngOnChanges(changes: SimpleChanges): void { for (const propName in changes) { const change = changes[propName];
}
public onButtonClick(button: Button) { this.onClick.next(button); }
ngOnDestroy(): void { // Unsubscribe per evitare memory leaks if (this.dropdownSub) { this.dropdownSub.unsubscribe(); } }
public onShown() { this.dropdownService.openDropdown(this.uuid); this.calculatePosition(); }
public hideDrop() { this.dropdown.hide(); }
public onHidden() { //this.resetPosition(); }
public calculatePosition() { if (this.dropdownMenu) { const hostBCR = this.ele.nativeElement.getBoundingClientRect(); const menuBCR = this.dropdownMenu.nativeElement.getBoundingClientRect();
}
isEmpty(btn: Button): boolean { return btn.label == '' && !btn.icon && !btn.iconRight; }}
sistemiUCSC priority commented 2 weeks ago
{{ buttonDropDown.label | translate }}{{ buttonDropDown.label2 | translate}} {{ buttonDropDown.counterValue }}
Arkadiusz Idzikowski staff commented 2 weeks ago
Are you sure that you use the MDB Angular dropdown component? I don't see the MDB component syntax anywhere in the attached code.
You can find the MDB Angular dropdown documentation here: https://mdbootstrap.com/docs/angular/components/dropdowns/
sistemiUCSC priority commented 2 weeks ago
when I insert the form the error I get is this: if I add it it gives me this error: "Cannot read properties of undefined (reading 'menuPositionClassChanged') "
Dropdown buttonenter code here
Arkadiusz Idzikowski staff commented 2 weeks ago
You probably get this error because you did not add
mdbDropdownMenu
directive to theul
HTML element. Please make sure to include all three directives (like in the examples in our documentation):mdbDropdown
,mdbDropdownToggle
andmdbDropdownMenu
.sistemiUCSC priority commented 2 weeks ago
I added this directive: ul mdbDropdownMenu class="dropdown-menu" aria-labelledby="dropdownMenuButton"> but the result doesn't change it keeps giving me the error: Cannot read properties of undefined (reading 'menuPositionClassChanged')
Arkadiusz Idzikowski staff commented 2 weeks ago
Like I mentioned in the previous comment, we need some more information in order to help you resolve this problem.
We won't be able to do that without knowing how did you configured MDB Angular in your application and what MDB Angular code did you use.
The code you provided looks like a custom Angular code which does not contain any MDB components.
sistemiUCSC priority commented 1 week ago
sistemiUCSC priority commented 1 week ago
mdbdropdown in the mdule: error: ngx-unicatt-global-error-handler.ts:31 Cannot read properties of undefined (reading 'menuPositionClassChanged')
ngx-unicatt-global-error-handler.ts:32 TypeError: Cannot read properties of undefined (reading 'menuPositionClassChanged') at MdbDropdownDirective._listenToMenuPositionClassChange (mdb-angular-ui-kit-dropdown.mjs:170:28) at MdbDropdownDirective.ngAfterContentInit (mdb-angular-ui-kit-dropdown.mjs:154:14) at callHookInternal (core.mjs:5150:14) at callHook (core.mjs:5177:13) at callHooks (core.mjs:5131:17) at executeInitAndCheckHooks (core.mjs:5081:9) at refreshView (core.mjs:13283:21) at detectChangesInView (core.mjs:13454:9) at detectChangesInViewIfAttached (core.mjs:13414:5) at detectChangesInEmbeddedViews (core.mjs:13373:13) ngx-unicatt-global-error-handler.ts:31 Cannot read properties of undefined (reading 'menuPositionClassChanged') ngx-unicatt-global-error-handler.ts:32 TypeError: Cannot read properties of undefined (reading 'menuPositionClassChanged')
sistemiUCSC priority commented 1 week ago
sistemiUCSC priority commented 1 week ago
the error is: ngx-unicatt-global-error-handler.ts:31 Cannot read properties of undefined (reading 'menuPositionClassChanged')
ngx-unicatt-global-error-handler.ts:32 TypeError: Cannot read properties of undefined (reading 'menuPositionClassChanged') at MdbDropdownDirective._listenToMenuPositionClassChange (mdb-angular-ui-kit-dropdown.mjs:170:28) at MdbDropdownDirective.ngAfterContentInit (mdb-angular-ui-kit-dropdown.mjs:154:14) at callHookInternal (core.mjs:5150:14) at callHook (core.mjs:5177:13) at callHooks (core.mjs:5131:17) at executeInitAndCheckHooks (core.mjs:5081:9) at refreshView (core.mjs:13283:21) at detectChangesInView (core.mjs:13454:9) at detectChangesInViewIfAttached (core.mjs:13414:5) at detectChangesInEmbeddedViews (core.mjs:13373:13) ngx-unicatt-global-error-handler.ts:31 Cannot read properties of undefined (reading 'menuPositionClassChanged') ngx-unicatt-global-error-handler.ts:32 TypeError: Cannot read properties of undefined (reading 'menuPositionClassChanged')
sistemiUCSC priority commented 1 week ago
Arkadiusz Idzikowski staff commented 1 week ago
Could you please test if this error occur when you replace the existing HTML code used to render the dropdown component with the code from our documentation?
Just to make sure that the error is not caused by the modifications added in your styles or TS code.
We tested the component on the examples from our documentation and we could not reproduce this issue.
sistemiUCSC priority commented 1 week ago
If you try again with your html and the problem persists
Arkadiusz Idzikowski staff commented 6 days ago
We have checked our component very carefully but we were not able to reproduce this problem in any way.
Such an error can appear when the
mdbDropdown
directive does not have access to themdbDropdownMenu
directive (when the element containing this directive does not exist or has been removed from the DOM).In case of further problems, please try to reproduce this bug by recreating this small part of your application where you use our component in a new Angular application that you could share with us. Maybe then it would be easier to find the cause of the problem.
sistemiUCSC priority commented 5 days ago
Arkadiusz Idzikowski staff commented 4 days ago
I think this is the same error message as mentioned before. The error originates from our component, but we were unable to reproduce it on our end based on the information provided in this topic.
Please try to reproduce it in a new Angular project as I suggested in my previous comment.