Solved

Question on menu in angular material design

Posted on 2016-07-14
5
83 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 53

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 53

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 53

Expert Comment

by:Julian Hansen
ID: 41717861
You are welcome
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

864 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now