0

I have a select that is dynamically populated on Angular:

<select material-select watch name="cat" id="cat"
ng-model="cat" ng-change="getSubcategoriesForThisCategory(cat)">
     <option ng-repeat="category in allCategories" value="{{category.id}}">{{category.name}}</option>
</select>

And here in the controller is where that variable is filled:

$scope.allCategories = $scope.request.getCategories();

When the value of this select changes the following happens:

$scope.getSubcategoriesForThisCategory = function(cat){
      $scope.allSubcategories = $scope.request.getSubcategoriesForSpecificCategory(cat);
    }

Will putting the following suffice or do I need to do something else? :

<select material-select watch name="subcat" id="subcat"
ng-model="subcat" ng-change="getSubcategoryData(subcat)">
      <option ng-repeat="subcategory in allSubcategories" value="{{subcategory.id}}">{{subcategory.name}}</option>
</select>

I have no way to prove whether this works or not since I have no access to the Laravel restful API nor the database, I just got a list of methods to call so I can get/create/update/delete (I know this is not optimal but it's what I got). Will the above "work"?

CodeTrooper
  • 1,890
  • 6
  • 32
  • 54
  • In principle it will work assuming that `$scope.request.getSubcategoriesForSpecificCategory(cat)` returns an array of objects. It is easy enough to mock the data yourself locally – charlietfl Jan 05 '16 at 14:30
  • I see no obvious problem. You could however create a static JSON file with a suitable structure (ie. categories with subcategories) and mock up your backend call. – Johannes Jander Jan 05 '16 at 14:30
  • @JohannesJander I wasn't sure whether that would work. I'm very new to Angular and a lot of things happen without me knowing how they work, they just do.. Seems to me like old VB.net.. Stuff happens and you have no idea why or how, they just do. Let me try and I'll get back to you so you can post it as an answer. – CodeTrooper Jan 05 '16 at 14:33
  • Good luck. You could read up on [NgMock](https://docs.angularjs.org/api/ngMock), [$httpBackend](https://docs.angularjs.org/api/ngMock/service/$httpBackend) and [here's](http://stackoverflow.com/questions/15854043/mock-a-service-in-order-to-test-a-controller) a Stackoverflow example – Johannes Jander Jan 05 '16 at 14:38

0 Answers0