Javascript 基于其他选择进行选择

Javascript 基于其他选择进行选择,javascript,html,angularjs,angularjs-ng-repeat,Javascript,Html,Angularjs,Angularjs Ng Repeat,关于AngularJS问题,我需要您的帮助:我希望有一个基于其他HTML的HTMLselect(这是一个非常常见的web问题)。我是这样完成这项任务的: 视图: 这可以正常工作,但我想了解为什么下面的解决方案不起作用。假设使用相同的控制器,视图变为: <div class="form-group"> <select data-ng-change="getOffices()" data-ng-model="selectedCustomer" data-ng-options

关于AngularJS问题,我需要您的帮助:我希望有一个基于其他HTML的HTML
select
(这是一个非常常见的web问题)。我是这样完成这项任务的:

视图:

这可以正常工作,但我想了解为什么下面的解决方案不起作用。假设使用相同的控制器,视图变为:

<div class="form-group">
    <select data-ng-change="getOffices()" data-ng-model="selectedCustomer" data-ng-options="customer.name for customer in customers" class="form-control">
        <option value="">Choose customer...</option>
    </select>
    <select class="form-control" data-ng-options="office.name for office in selectedCustomer.offices.getAll">
        <option value="">Choose office...</option>
    </select>
</div>

您需要这样做,请参阅$resource上的angular文档

 angular.module("app").controller("receiptsController", ["$scope",GetOffices
        function ($scope,GetOffices){

            //selected customer
            $scope.selectedCustomer = null;

            //get offices related to the selected customer
            $scope.getOffices = function(){
                if($scope.selectedCustomer !== null)
                    $scope.selectedCustomer=GetOffices.get({customerID:123});
            };
    }]);

你能把
getOffices()
方法的代码也发出来吗?我编辑了这篇文章,写了getOffices()的代码。在getOffices()方法中,有一个类似于您的ajax调用。
<div class="form-group">
    <select data-ng-change="getOffices()" data-ng-model="selectedCustomer" data-ng-options="customer.name for customer in customers" class="form-control">
        <option value="">Choose customer...</option>
    </select>
    <select class="form-control" data-ng-options="office.name for office in selectedCustomer.offices.getAll">
        <option value="">Choose office...</option>
    </select>
</div>
angular.module("app").factory("GetOffices", ["$resource", 
    function($resource){
        return $resource("../retrieveOffices.php",
        {customerID:'@id'});
}]);
 angular.module("app").controller("receiptsController", ["$scope",GetOffices
        function ($scope,GetOffices){

            //selected customer
            $scope.selectedCustomer = null;

            //get offices related to the selected customer
            $scope.getOffices = function(){
                if($scope.selectedCustomer !== null)
                    $scope.selectedCustomer=GetOffices.get({customerID:123});
            };
    }]);