简体   繁体   中英

Calling function on dropdown AngularJS

I have an interesting scenario happening right now and it's confusing me, this question is initially meant for those who are familiar with Angular UI Grid. However, you are welcome to answer.

I have a UI Grid that I call a drop down through a separate html page in the grid itself because the dropdown values dynamically change. Now I have ng-model of this drop as ng-model="row.entity.someValue" this would be the value of the $scope.someDate.someValue that is obtained from the grid with field: 'someValue' . The issue I'm having at hand is after selection I cannot fire a function call, I'm avoiding id="" calls because I want the code to be consistent and not use getElementById calls. I've tried ng-selected, ng-change even ng-class (knowing it wouldn't work) What I'm trying to do is fire a function with the selected value as a parameter and I cannot get the function to fire. What am I missing here?

Here is a same code of what I'm trying to achieve:

 <div>
    <select ng-model="row.entity.someValue" class="dropdownWidth" ng-selected="someFunction(selectedValue)" >
        <option ng-repeat="selectedValue in grid.appScope.someArray" value={{selectedValue}}>{{selectedValue}}</option>
    </select>
</div>

UPDATE Answer below

The answer was right there in front of me, which I keep forgetting. Every time a call to a grid cell is made outside of the controller you always apply grid.appScope in anything thing pertaining to the cell's value

in my case I was just calling ng-selected="someFunction(selectedValue)" when in fact I should've been calling ng-selected="grid.appScope.someFunction(row.entity.someValue)" . Now it works perfectly, hopefully this scenario will be of some good use for anyone in the future!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM