简体   繁体   English

用ng-options进行ng-change witing select不起作用

[英]ng-change witing select with ng-options not working

I have this code 我有这个代码

<select  ng-model="trabajadores.orderSelected"  ng-options="excel for excel in trabajadores.csv.result[1]" ng-change="console.log('changed')">
                        </select>

It suppose to console.log("changed") on selection changes, but it does not :(. Can you please help me with this issue?. (ng-options is working properly and ng-model is been evaluated) 它假定对console.log(“ changed”)进行了选择更改,但它不是:(。您能帮我解决这个问题吗?。(ng-options正常工作,并且ng-model已评估)

If during development you want to use the output in the console of the view many times, it is not convenient to write under each time this function. 如果在开发过程中要多次使用视图的console中的输出,则每次使用此功能编写时都不方便。

It is best to proceed as follows. 最好按以下步骤进行。 Use the built-in angular directive $log . 使用内置的角度指令$log

Live example on jsfidlle . jsfidlle上的实时示例。

 var app = angular.module('my-app', [], function() {}).run(function($rootScope,$log){ $rootScope.$log = $log; }); app.controller('AppController', function($scope) { $scope.trabajadores = { csv: { result: [0, ['e1', 'e2']] } }; }) 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="my-app"> <div ng-controller="AppController"> <select ng-model="trabajadores.orderSelected" ng-options="excel for excel in trabajadores.csv.result[1]" ng-change="$log.log('changed '+ trabajadores.orderSelected)"> </select> </div> </div> 

Of course, you can not leave this production code. 当然,您不能离开此生产代码。 But for debug mode it can be fully used. 但是对于debug模式,它可以完全使用。

With this you can use the $log in any controller without any additional work. 这样,您可以在任何控制器中使用$log ,而无需进行任何其他工作。

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

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