Populate Dropdown 2 based on Dropdown 1 selection

前端 未结 3 1510
再見小時候
再見小時候 2020-11-30 08:55

I am able to populate 2 dropdowns directly from database. My problem is, the 2nd dropdown values has to be populated based on the 1st dropdown selection. Since i am new to

3条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 09:29

    Do it like this:

    
    
    

    With javascript you just need only one controller, the office controller:

    angular.module('myApp',[])
    .controller('OfficeCtrl', 
    ['$scope','$location','OfficeNames','OfficeObjCode',function($scope, 
    $location, OfficeNames,OfficeObjCode)
    {
    $scope.Offices=OfficeNames.query();
    
    $scope.updateObjects =function(office_id)
    {`// take {{office_id}} to server to pick codes based 
        //on that office id and
        // then assign them to $scope.codes..`
    
    $scope.Codes = 'what you came back with';
    }
    
    }).factory('OfficeNames', function ($resource) {
    return $resource(
        'api/Office/:id',
        { id: '@id' },
        { update: { method: 'PUT' } }
    );
    }).factory('OfficeObjCode', function ($resource) {
    return $resource(
        'api/OfficeObj/:id',
        { id: '@id' },
        { update: { method: 'PUT' } }
    );
    });
    

提交回复
热议问题