I am encountering a dilemma on how to insert a variable from an array into a query string. The filter function is functioning properly, but the search function seems to be ineffective. The variable 'id' successfully retrieves the id from the selected user, however, the subsequent 'vm.search' does not yield any results. As I am relatively new to Angular and JavaScript, I might be overlooking something quite simple. Below is my code snippet:
(function () {
'use strict';
angular
.module('app.pil')
.controller('userListController', ctrl);
ctrl.$inject = ['$rootScope', 'users', 'pilService', 'notificator'];
function ctrl($rootScope, users, pilService, notificator) {
var vm = this;
vm.filter = function () {
vm.users = users;
vm.users = pilService.filter.query(vm.data);
};
vm.search = function () {
var id = vm.users[0].id;
vm.search = pilService.search.query(id);
}
}
})();
Thanks for any insights!
pilService code:
(function () {
'use strict';
angular.module('app.pil').factory('pilService', service);
service.$inject = ['CONFIG', '$resource'];
function service(CONFIG, $resource) {
var users = $resource(CONFIG.API_END_POINT_URL + '/pil/api/pilot/clients', {}, {
query: {isArray: true},
update: {method: 'GET'}
});
var filter = $resource(CONFIG.API_END_POINT_URL + '/pil/api/pilot/clients/filter', {}, {
query: {isArray: true},
update: {method: 'GET'}
});
var search = $resource(CONFIG.API_END_POINT_URL + '/pil/api/pilot/clients/search', {}, {
query: {isArray: true},
update: {method: 'GET'}
});
return {users: users,
filter:filter,
search:search
}
}
})();