Javascript 下拉列表更改时在控制器内部调用函数

Javascript 下拉列表更改时在控制器内部调用函数,javascript,angularjs,Javascript,Angularjs,我的Angular.JS控制器文件中包含以下代码: JBenchApp.controller('CaseListCtrl', ['$scope', '$http', function ($scope, $http) { // Case list stuff here $http.get('http://10.34.34.46/BenchViewServices/api/Calendar/LA/5/08-27-2015').success(function (

我的Angular.JS控制器文件中包含以下代码:

JBenchApp.controller('CaseListCtrl', ['$scope', '$http', 
  function ($scope, $http) {
      // Case list stuff here
          $http.get('http://10.34.34.46/BenchViewServices/api/Calendar/LA/5/08-27-2015').success(function (response) {
              $scope.cases = response;
          });

          $http.get('http://10.34.34.46/BenchViewServices/api/CourtDept/LA').success(function (response) {
              $scope.departments = response;
          });
  }]);
cases变量包含所选法庭部门的事件列表。我想做的是更改它,以便在UI中发生变化时刷新案例。例如,部门是下拉列表的一部分,当我更改部门时,我希望更改cases变量以包含新选择的法庭部门的事件。此外,我有一个日期选择器,当它更改时,我希望cases变量包含当前选定法庭部门新选定日期的通风口

编辑从这里开始:我知道我可以使用ng change绑定到$scope函数,如下所示:

JBenchApp.controller('CaseListCtrl', ['$scope', '$http', 
  function ($scope, $http) {
      // Case list stuff here
      $scope.getCalendar = function () {
          $http.get('http://10.34.34.46/BenchViewServices/api/Calendar/LA/5/08-27-2015').success(function (response) {
              $scope.cases = response;
          });
      }

          $http.get('http://10.34.34.46/BenchViewServices/api/CourtDept/LA').success(function (response) {
              $scope.departments = response;
          });
  }]);
<select ng-change="updateCase()">
然而,我也明白为了使用ng变更,我需要一个ng模型。这就引出了两个问题:

由于部门也是动态加载的,我如何设置部门的模型?我已经将其设置为$scope。部门…是否正确? 当日历屏幕加载时,如何进行日历内容的初始加载? 您在下拉列表中做了一个ng更改,如下所示:

JBenchApp.controller('CaseListCtrl', ['$scope', '$http', 
  function ($scope, $http) {
      // Case list stuff here
      $scope.getCalendar = function () {
          $http.get('http://10.34.34.46/BenchViewServices/api/Calendar/LA/5/08-27-2015').success(function (response) {
              $scope.cases = response;
          });
      }

          $http.get('http://10.34.34.46/BenchViewServices/api/CourtDept/LA').success(function (response) {
              $scope.departments = response;
          });
  }]);
<select ng-change="updateCase()">
您可以使用,也可以在控制器中使用。

您可以使用ng change指令

差不多

<input ng-model = 'someModel' ng-change = 'someChangeFunction()' />

您应该更改

您可以将作用域方法绑定到下拉列表中的ng change,前提是它具有ng模型。下面是一个选择中的ng更改示例:@james您能向我解释一下您的模型项在控制器中是如何显示的吗?当在选择/下拉列表中选择一个值时,在这种情况下,项将更新为该值,具有代码和名称的对象。ngModel指令将所选值绑定到当前范围请参见。如何针对从数据库动态获取的部门设置模型?上面给出的答案示例具有硬编码的值。