javascript - AngularJS ng-change on select with custom directive -


in application have custom directive select tag.

<div class="row pv10" ng-if="item.visible">   <div class="col-xs-4 text-danger"><span ng-if="item.label_visible"> {{item.label}}</span></div>      <div class="col-xs-8">         <div class="row">           <div class="col-xs-1">             <select ng-options="oneitem oneitem in item.options" ng-model="selecteditem" ng-change="changeevent()">                 {{selecteditem | json}}             </select>           </div>       </div>    </div> </div> 

i perform action on every change event. tought of using ng-change, btw. worked fine radiobtn/checkbox.i tried 2 approaches here.

firstly tried pass "changeevent" function directive's isolated scope.

<custom-select item='item' change-event="change()" ng-if="item.component == 'select'" /> 

changeevent() function exists in current controller (attached view holding custom-select)

scope: {         item: "=",         changeevent: "&"     } 

sadly expression not evalue on change. secondly tried attach function directly directive

link: function ($scope, elems, attrs) {         $scope.changeevent = function () {             alert("change event!");         }     } 

but didn't work either.

i read somewhere ng-change used within custom directive operates on controllers scope, not isolated scope of directive. not quite sure that. i'd appreciate help. thank you!

edit!

this jsfiddle directive use. if should provide more details, let me know, first time i've ever used jsfiddle.

this how directive invoked:

<div class="row" ng-repeat="item in jsondata">   <div class="col-xs-12">        <cbp-select item='item' change="change()" ng-if="item.component == 'select'" />   </div> </div> 

https://jsfiddle.net/60nsfg0l/

edit2

when have uploaded solution our local server started work properly.(yes, cleaned browser's cash, , locals wamp/iss cache too). have different problem. have form built different directives(like 1 above), have ng-click/change/blur. seems work fine until change 1 of options in "select" directive. after selecting 1 of values, ng-change expression triggered(for not simple alert) , moment onwards not able focus on other elements. weirdly enough, if cause ng-change trigger on other element radiobtn or checkbox problem not occur


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -