2014-05-07 13 views
5

trong Angularjs tôi đã thêm sau chọn điều khiển mà nghe cho một sự kiện thay đổiAngularJS NgChange không được gọi

<select ng-model="Ruoli" ng-options="ruolo.Nome for ruolo in ruoli" class="form-control" ng-change="setNotRuolo(Ruoli.Id)"></select> 

Khi tôi chọn một mục chức năng

setNotRuolo()

được gọi chính xác nhưng khi tôi thay đổi các mục bằng cách sử dụng phím xuống trên bàn phím mà chức năng không được gọi.

Tôi làm cách nào để khắc phục sự cố này?

+0

Bạn có thể tạo ra một câu đố hoặc plunker? Điều đó sẽ giúp xác định sự cố – Satpal

+2

Đây là lỗi đã biết: https://github.com/angular/angular.js/issues/4216#issuecomment-25872117 Giải pháp: http://plnkr.co/edit/ccL4Y1LWSOz22o6SZHLS? p = preview – Dieterg

+0

https://github.com/angular/angular.js/issues/2616 Bạn sử dụng phiên bản góc nào? Điều này đã xảy ra chỉ trong firefox, mà còn trong Chrome? – Getz

Trả lời

0

Đây là một vấn đề mà đã được thảo luận tại GitHub

Chỉ cần có một cái nhìn tại

Working Demo

html này

<div ng-app='myApp' ng-controller="Controller"> 
    <label for="browsers">Pick A Name:</label> 
    <form name="myForm"> 
     <select dselect required id="browsers" ng-model="selectValue" ng-options="browser for browser in browsers"> 
      <option value="">Select One</option> 
     </select> 
     <br> 
     <button ng-click="submit()" ng-disabled="!myForm.$valid">submit</button> 
    </form> 
    <br> 
    <br>You Selected: {{selectValue || "You didn't pick"}}</div> 
</div> 

script

var app = angular.module('myApp', []); 

app.controller('Controller', function ($scope) { 
    $scope.browsers = ['Manu', 'Mathew', 'Sunny']; 
    $scope.submit = function() { 
     alert("submit"); 
    } 
}); 
if (navigator.userAgent.indexOf("Sunny") !== -1) { 
    app.directive("select", function() { 
     return { 
      restrict: "E", 
      require: "?ngModel", 
      scope: false, 
      link: function (scope, element, attrs, ngModel) { 
       if (!ngModel) { 
        return; 
       } 
       element.bind("keyup", function() { 
        element.trigger("change"); 
       }) 
      } 
     } 
    }) 
} 
+0

Điều này không trả lời được câu hỏi theo bất kỳ cách nào. – WMios

Các vấn đề liên quan