简体   繁体   English

ng-select中的更改不起作用

[英]ng-change in select not working

I'm trying to update a list2 from a list1, and i used ng-change for that. 我正在尝试从list1更新list2,为此我使用了ng-change。

My app is fully configured and the controller for the html page is well setted. 我的应用程序已完全配置,并且html页面的控制器设置正确。

The only thing that when i select the elemt from my first list1 the method updateList2 never invocked 当我从第一个list1中选择elemt时,唯一没有发生过调用updateList2方法的情况

<label>NameLIst1</label>
<select ng-model="idLIST1" 
        ng-change="updateList2(idLIST1)"
        ng-options="elt.id as elt.name for elt in list1">

        <option  value="">select one</option>
</select>

<label>Name LIST 2</label>
<select  ng-model="idLIST2"                 
        ng-options="elt.id as id.name for elt in list2">

        <option  value="">select one</option>
</select>


$scope.updateList2 = function(id){
alert("id ="+id);
}

I have code which are written in below ,try this it's work fine,also work with param, but you don't need to pass param in methods 我有下面编写的代码,请尝试使用它,也可以使用param,但是您无需在方法中传递param

<div class="container" ng-controller="TestController">
    <label>NameLIst1</label>
    <select ng-model="idLIST1"
            ng-change="updateList2(idLIST1)"
            ng-options="elt.id as elt.name for elt in list1">

        <option value="">select one</option>
    </select>

    <label>Name LIST 2</label>
    <select ng-model="idLIST2"
            ng-options="elt.id as id.name for elt in list2">

        <option value="">select one</option>
    </select>
</div>

var app = angular.module("test", ["ngRoute"])
        .controller("TestController", ['$scope', function ($scope) {
            $scope.list1 = [
               { id: 1, name: 'data1' },
               { id: 2, name: 'data2' },
               { id: 3, name: 'data3' },
               { id: 4, name: 'data4' },
            ];
            $scope.updateList2 = function (id) {
                alert("id =" + id);
            }
        }
        ]);

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

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