sovanna / angular-material-sidenav

Simple component that reproduce the Angular Material Style SideNav Menu from their own website
http://sovanna.github.io/angular-material-sidenav/
109 stars 55 forks source link

ssSideNav.selectSection doesn't work #12

Closed d668 closed 8 years ago

d668 commented 8 years ago

I assume ssSideNav.selectSection should open a section? I am adding following code to _common.js

$timeout(function () {
            alert('select common.toggle1.item1')
            ssSideNav.selectSection('common.toggle1.item1');
            //ssSideNav.selectSection('toogle_1_link_1'); //both don't work

}, 4000);
sovanna commented 8 years ago

Hi, sorry ! I didn't update the documentation yet. With other user's pull-request, we've changed some of the original implementation.

You should look at demo code

d668 commented 8 years ago

i've looked through the example and still don't get how do I select a menu item. Because if my user logs in, I want to change the menu and show him some specific item. And with the current project seems like i can do it only if i use ssSideNavSectionsProvider.initWithSections

sovanna commented 8 years ago

one, you config your menu using provider ssSideNavSectionsProvider.initWithSections in app.config. inWithSections(array), the array contains menu item (an object keys/values) in where you can add a key hidden

example: { id: 'link_3', name: 'Link 3', state: 'common.link3', type: 'link', hidden: true } by default, hidden is set to false if you not provided

then, if you want to hide/show, use setVisible(id, value) => setVisible('link_3', true) in your controller.

If you want to replace all of the menu items config, in your controller, you can do ssSideNav.sections = [{//new item}, {//new item}, etc]

d668 commented 8 years ago

thanks for the explanation, but I still don't understand if selectSection is deprecated, what is a replacement? setVisible doesn't open the menu. Also initializing menu at config is too early for me

d668 commented 8 years ago

any update here please? How to open children menu programmatically?

sovanna commented 8 years ago

mm selectSection is not intend to be used like that.

if you want to open children menu, it basically means that you change the url (state) in your app. So to do that, you just have to change your state. e.g:

$state.go('common.toggle1.item2')

which result to load the url /item2, which will open the dropdown menu "toggle1" in the demo app

d668 commented 8 years ago

i guess this may work if the menu is initiated in config, but if I assign sections ssSideNav.sections = menuForSomeRole; it doesn't work when using ui-sref or $state.go I have several roles and i assign menu dynamically. Is your lib supposed to work only with one menu? Thanks

sovanna commented 8 years ago

yes, you can change the entire menu as you want, but it appears, that it does not actually open the dropdown section when sub item is selected, i'm working on it

d668 commented 8 years ago

ok cool. thanks

sovanna commented 8 years ago

i've pushed a new version. You can now do ssSideNav.forceSelectionWithId('ID'); which results to select the child item on an dropdown menu sections and select its state name.

Let me know if its works for you.

thx.

d668 commented 8 years ago

is appears working, although inside controller i have to put it inside $timeout $timeout(function () { ssSideNav.forceSelectionWithId(vm.stateName); }, 100); And what is supposed styling of a selected menu item? thank you!