Solved

Question on menu in angular material design

Posted on 2016-07-14
5
116 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 56

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 56

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 56

Expert Comment

by:Julian Hansen
ID: 41717861
You are welcome
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Find out what you should include to make the best professional email signature for your organization.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

756 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