Solved

Question on menu in angular material design

Posted on 2016-07-14
5
92 Views
Last Modified: 2016-07-18
I am working on google material design and angularjs frameworks and in my page I have small menu with Option1,Option2 and Option3. Here is the pen menu demo. In this example I am passing $index to the function to know which option user has selected.

1) Can we  acheive "Option1/Option2/Option3 selected"  without using $index. ?

2)When we click on Option1/Option2/Option3 items in menu, it will bring Prompt dialog  I want submit button and want to call API to fetch data on click of submit button.How can I achieve this? eg: Option1Click(), Option2Click(),Option3Click()
0
Comment
Question by:ksd123
  • 3
  • 2
5 Comments
 
LVL 54

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 41712603
With the ng-repeat you can pass item to the ng-click in other words
            <md-menu-item ng-repeat="item in [1, 2, 3]">
              <md-button ng-click="ctrl.announceClick(item)"> <span md-menu-align-target="">Option</span> {{item}} </md-button>
            </md-menu-item>

Open in new window

This much more useful than index because if you are iterating over an array of objects with other information you may need - your ng-click gets the complete object in the event handler.
0
 

Author Comment

by:ksd123
ID: 41715869
Thank you.I need one more suggestion . Actually I have 6 Options (Option1,Option2....Option6) in the menu and for each Option click I have to implement different business logic and need to pass parameters . I am planning to implement in the following way.Please let me know if this is best way do this.
mycontroller.js

this.menuClick = function(item,Parameter1) {
if(item=='Option1')
{
Option1Click();
}

if(item=='Option2')
{
Option2Click();
}
    );

Open in new window


Thanks in advance
0
 
LVL 54

Expert Comment

by:Julian Hansen
ID: 41715918
I am assuming your question is about moving the functionality for each option click out to a separate function as opposed to having the functionality in the ng-click handler?

Yes, this is advisable - it makes your handler easier to understand.
0
 

Author Closing Comment

by:ksd123
ID: 41717582
Thank you
0
 
LVL 54

Expert Comment

by:Julian Hansen
ID: 41717861
You are welcome
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question