Solved

Question on menu in angular material design

Posted on 2016-07-14
5
123 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 57

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 57

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 57

Expert Comment

by:Julian Hansen
ID: 41717861
You are welcome
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Set css in function 11 56
How to open a new browser tab after executing php script 20 49
Div not showing up 6 33
ajax post without refreshing whole page 10 23
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

752 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