I have come across a quite peculiar error on my AngularJS code of a web application.
I have an application which has a form for inserting new data in the database, but before that it's going to look for any coincidences.
Now, the object that we insert in database has a series of collections and if it already exists the application will show the whole content on the UI, where the user will be able to add new items to the collections
The collections are made of entities which each have their own view and independent access to them from the navbar menu, so when I call the add new item method in the form it's actually recycled from the previous one, and here is the funny part
I have done three of them in the form and they all work fine, same view shows, same functionality, but when I try with the fourth one, this error comes up:
angular.js:13294 Error: [$injector:unpr] Unknown provider: pagingParamsProvider <- pagingParams <- TreatmentController2
http://errors.angularjs.org/1.5.2/$injector/unpr?p0=pagingParamsProvider%20%3C-%20pagingParams%20%3C-%20TreatmentController
Now, the even funnier thing is that I am using the same code for the controller and for the view as what is used on the separate entity view access, yet when I do it from the form it won't work.
If I remove the paging params injection, it loads the view, but of course, it loses all functionality.
Here's the code:
Controller:
(function() {
'use strict';
angular
.module('vivaxDataManagerApp')
.controller('TreatmentController', TreatmentController);
TreatmentController.$inject = ['$scope', '$state', 'Treatment', 'TreatmentSearch', 'ParseLinks', 'AlertService', 'pagingParams', 'paginationConstants'];
function TreatmentController ($scope, $state, Treatment, TreatmentSearch, ParseLinks, AlertService, pagingParams, paginationConstants) {
var vm = this;
vm.loadAll = loadAll;
vm.loadPage = loadPage;
vm.predicate = pagingParams.predicate;
vm.reverse = pagingParams.ascending;
vm.transition = transition;
vm.clear = clear;
vm.search = search;
vm.searchQuery = pagingParams.search;
vm.currentSearch = pagingParams.search;
vm.loadAll();
function loadAll () {
if (pagingParams.search) {
TreatmentSearch.query({
query: pagingParams.search,
page: pagingParams.page - 1,
size: paginationConstants.itemsPerPage,
sort: sort()
}, onSuccess, onError);
} else {
Treatment.query({
page: pagingParams.page - 1,
size: paginationConstants.itemsPerPage,
sort: sort()
}, onSuccess, onError);
}
function sort() {
var result = [vm.predicate + ',' + (vm.reverse ? 'asc' : 'desc')];
if (vm.predicate !== 'id') {
result.push('id');
}
return result;
}
function onSuccess(data, headers) {
vm.links = ParseLinks.parse(headers('link'));
vm.totalItems = headers('X-Total-Count');
vm.queryCount = vm.totalItems;
vm.treatments = data;
vm.page = pagingParams.page;
}
function onError(error) {
AlertService.error(error.data.message);
}
}
function loadPage (page) {
vm.page = page;
vm.transition();
}
function transition () {
$state.transitionTo($state.$current, {
page: vm.page,
sort: vm.predicate + ',' + (vm.reverse ? 'asc' : 'desc'),
search: vm.currentSearch
});
}
function search (searchQuery) {
if (!searchQuery){
return vm.clear();
}
vm.links = null;
vm.page = 1;
vm.predicate = '_score';
vm.reverse = false;
vm.currentSearch = searchQuery;
vm.transition();
}
function clear () {
vm.links = null;
vm.page = 1;
vm.predicate = 'id';
vm.reverse = true;
vm.currentSearch = null;
vm.transition();
}
}
})();
The call from the HTML code:
<div class="form-group-row">
<label class="col-md-2 form-control-label">Insert new Treatment:</label>
<div class="col-md-2">
<a class="btn btn-success" ng-click="newTreatment()">
<span class="glyphicon glyphicon-plus"/>
</a>
</div>
</div>
The function in the form controller:
$scope.newTreatment = function () {
$scope.myHidingValue=true;
$uibModal.open({
templateUrl: 'app/entities/treatment/treatment-dialog.html',
controller: 'TreatmentController',
size: 'lg',
controllerAs: 'vm',
backdrop: 'static',
resolve: {
entity: function () {
return {};
}
}
}).result.then(function (result) {
$scope.publi = result;
}, function () {
})
};
I'm only posting what I think is the most relevant code, as I have thousands of lines in this project, but if necessary, I don't mind posting more code
Thank you all in advance
Steven