0

i have following code i have more then one object in return how to get these please help check below code and image file

 .then(response => {
        this.jobCategories = response.data;
        console.log(response.data);
        this.jobCategories.categories.sort(function(a,b){

          a.child_categories.sort();

           return a.category_name > b.category_name;

        });
        this.selectedCategoryL1 = this.jobCategories.categories[0];
        this.selectedCategoryL2 = this.selectedCategoryL1.child_categories[0];
      });

//MY DROP DOWN

<select class="form-control ng-pristine ng-valid ng-not-empty ng-touched" name="category" id="category" ng-model="postjobcustomerCtrl.selectedCategoryL1" ng-options="category.category_name for category in postjobcustomerCtrl.jobCategories.categories | orderBy:'category_name' track by category.category_name" ng-change="postjobcustomerCtrl.changeChildCategory()" aria-invalid="false" style=""></select>

Sub Category

<select class="form-control" name="subcategory" id="subcategory" ng-model="postjobcustomerCtrl.selectedCategoryL2" ng-options="option for option in postjobcustomerCtrl.selectedCategoryL1.child_categories | orderBy"></select>

enter image description here

enter image description here

5
  • not exactly clear what your asking for, whats your expected outcome? Commented Nov 16, 2016 at 17:38
  • i have drop down selectedcategoryL1, i want show data in this dropdown Commented Nov 16, 2016 at 17:41
  • if the above code is in your controller, this. selectedCategoryL1 is no longer the lexical $scope 'this'. you need to set this to a var outside of the method or use $scope. selectedCategoryL1. Commented Nov 16, 2016 at 17:43
  • how......... > ?? Commented Nov 16, 2016 at 17:46
  • Please include data and error messages as text, not images. Commented Nov 16, 2016 at 18:01

1 Answer 1

0

Please take a look at the following, I think this is problem.
if the above code is in your controller, this. selectedCategoryL1 is no longer the lexical $scope 'this'. you need to set this to a var outside of the method or use $scope. selectedCategoryL1.

var vm = this;
//or use $scope.selectedCategoryL1


.then(response => {
  this.jobCategories = response.data;
  console.log(response.data);
  this.jobCategories.categories.sort(function(a, b) {

    a.child_categories.sort();

    return a.category_name > b.category_name;

  });
  //or replace vm with $scope.
  vm.selectedCategoryL1 = this.jobCategories.categories[0];
  vm.selectedCategoryL2 = this.selectedCategoryL1.child_categories[0];
});
Sign up to request clarification or add additional context in comments.

3 Comments

could you share more of your controller and how your using it in the view
are you still getting undefined? if your remove your drop down, do you get the error?
can you show me how you updated your code after I suggested using vm or $scope.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.