Solved

Question on menu in angular material design

Posted on 2016-07-14
5
74 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 51

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 51

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 51

Expert Comment

by:Julian Hansen
ID: 41717861
You are welcome
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
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…

705 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

16 Experts available now in Live!

Get 1:1 Help Now