简体   繁体   English

在下拉菜单 AngularJS 上调用函数

[英]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.我现在正在发生一个有趣的场景,这让我很困惑,这个问题最初是为那些熟悉 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.我有一个 UI 网格,我通过网格本身的单独 html 页面调用下拉列表,因为下拉值动态变化。 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' .现在我有这个 drop 的ng-model="row.entity.someValue"作为ng-model="row.entity.someValue"这将是 $scope.someDate.someValue 的值,它是从带有field: 'someValue'的网格中获得的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.我手头的问题是选择后我无法触发函数调用,我避免 id="" 调用,因为我希望代码保持一致并且不使用 getElementById 调用。 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.我已经尝试过 ng-selected、ng-change 甚至 ng-class(知道它不起作用)我想要做的是用选定的值作为参数触发一个函数,但我无法触发该函数。 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每次在控制器外部调用网格单元时,您总是将grid.appScope应用于与单元格值有关的任何事物

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)" .就我而言,我只是在调用ng-selected="someFunction(selectedValue)" ,而实际上我应该调用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!现在它完美运行,希望这个场景对未来的任何人都有用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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