0

I have my code in angularjs and nodes js.

I have created a form in which there is two drop-down lists, the second drop-down list is dependent on the first dropdown list selected value, so the dropped down list selected value should be pass in the URL and in the backend options related to that selected id should be fetched for the second drop-down list.

My codes are: Html Code: In this code second select tag is empty

<div class="form-group" ng-controller="viewCompanyCtrl">
    <label class="col-sm-2 control-label">Company: </label>

    <div class="col-sm-10">
        <select class="form-control m-b" ng-valid ng-not-empty
                ng-model="recom.compName",id ="company"  name="account"
                ng-options = "x as x.compName for x in companyInfo">
        </select>
    </div>
</div>

<div class="form-group">
    <label style="position: relative; left:15px; top: 30px">Demographics:</label>

    <div style = "position: relative; left:196px">
        <select multiple chosen class="chosen-select" ng-valid ng-not-empty 
                ng-model="recom.demo",id ="demo" name="account8"  tabindex="4"
                style = "width:890px;" >
        </select>
    </div>
</div>

controller.js (through this function the values are shown in first list)

function viewCompanyCtrl($scope,$http,$state)
{
    $http.get('/viewCompany')
    .success(function(data){
        $scope.companyInfo = data;
        console.log($scope.companyInfo);
    })
    .error(function(){
        console.log("error");
    })

config.js(this is the state of the page)

.state('Admin.AddRecommendation',{
    url: "/AddRecommendation/:compId",
    templateUrl: "views/AddRecommendation.html",
    params: {compId:null},
})

Please help how to pass the id and get it in the backend.

Thanks

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Utkarsh Goyal
  • 23
  • 1
  • 5

1 Answers1

0

The .success method had been removed from the AngularJS framework.

To pass a URL parameter in an HTTP get request, use the params property:

var params = { compname: $scope.recom.compName };
var config = { params };
$http.get(url, config)
  .then(function(response) {
    var data = response.data;
    console.log(data);
}).catch(function(response) {
    console.log("ERROR: ", response);
});

For more information, see

georgeawg
  • 48,608
  • 13
  • 72
  • 95