angularjs - how to get selected element in angular js -


i trying selected value of menu option .actually in demo when click button show menu option want selected element text when user click select option menu , hide menu .

how selected item menu or selected text menu .first click button show menu item select element menu element menu. http://codepen.io/anon/pen/rpaoqy

   link:function(scope,element,attr){                  $(element).menu();               $(element).bind('click',function(){                   alert('--')                   ismenuvisibles=false;               }) 

directives designed integrate 3rd party libraries (such jquery-ui menu in use case)

use proper convention

nope - <ul custommenu ismenuvisible="ismenuvisible"

good - <ul custommenu is-menu-visible="ismenuvisible"

when using directive parameters, case changes in html , in definition. read more here

normalization

angular normalizes element's tag , attribute name determine elements match directives. typically refer directives case-sensitive camelcase normalized name (e.g. ngmodel). however, since html case-insensitive, refer directives in dom lower-case forms, typically using dash-delimited attributes on dom elements (e.g. ng-model).

the normalization process follows:

strip x- , data- front of element/attributes. convert :, -, or _-delimited name camelcase. example, following forms equivalent , match ngbind directive:


to sum up,

i modify snippet this:

http://codepen.io/jossef/pen/enzobv

html

  <div class="menu" ng-show="ismenuvisible">     <ul custommenu is-menu-visible="ismenuvisible" selected-menu-item="selecteditem">       <li class="ui-state-disabled">aberdeen</li>       <li>ada</li>       ... 

js

app.directive('custommenu', function($timeout) {       return {         restrict: 'a',         scope: {           ismenuvisible: '=',           selectedmenuitem: '='         },         link: function(scope, element, attr) {           $(element).menu({             select: function(event, ui) {               scope.selectedmenuitem = ui.item.text();               scope.ismenuvisible = false;               $timeout(angular.noop);             }           });          }       }     }) 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -