I just started learning AngularJS. I know this has been asked multiple times, but I am just not getting it. I've been at this for hours now, between reading example code here and fiddling about in my IDE.
I have the following code which is supposed to retrieve a section key for an item and then pass that key to a service which consumes an API to provide a response which populates the categories based on that key. This happens when a section table row is clicked.
The HTML
<div ng-controller="menuController">
<h1>AngularTest</h1>
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<tbody>
<tr ng-click="getSectionID($event)" ng-repeat-start="section in navSectionList" data-id="{{section.id}}">
<td>{{section.id}}</td>
<td>{{section.name}}</td>
</tr>
<tr ng-repeat-end="categories in navGetCategories">
<td>{{categories.id}}</td>
<td>{{categories.name}}</td>
</tr>
</tbody>
</table>
</div>
navController.js
var navApp = angular.module('navApp', ['ngResource']);
navApp.controller('menuController', ['$scope', 'navSectionList', 'navGetCategories',
function ($scope, navSectionList, navGetCategories) {
$scope.navSectionList = navSectionList.query();
$scope.getSectionID = function (event) {
var sectionID = event.currentTarget.attributes["data-id"].value;
$scope.sectionID = sectionID;
//console.log($scope.sectionID);
$scope.navGetCategories = navGetCategories.query(sectionID);
};
}
]);
navService.js
navApp.factory('navSectionList', [
'$resource', function ($resource) {
return $resource('/api/navigation/section/list', {}, {
query: { method: 'GET', params: {}, isArray: true }
});
}
]);
navApp.factory('navGetCategories', [
'$resource', function ($resource) {
return $resource('/api/navigation/category/' + sectionID, {}, {
query: { method: 'GET', params: {}, isArray: true }
});
}
]);
How do I get the value from the navController to the navService so that it can use that value to query the API? I feel like this should be something incredibly simple and basic but I'm either lacking sleep or lacking smarts at the moment. Please help.