Currently, I am in the process of enhancing a web application that was originally developed using AngularJS with typescript instead of JS.
I have a controller set up with a specific template that I want to display in a modal using $modal.open.
However, I keep encountering an error message that says "Error: [$controller:ctrlreg] The controller with the name 'AddWeightCtrl' is not registered." Despite searching on various platforms, including Stack Overflow, I haven't found a solution that fits my scenario.
When attempting to open the modal, this error occurs...
Error: [$controller:ctrlreg] The controller with the name 'AddWeightCtrl' is not registered. https://errors.angularjs.org/1.7.9/$controller/ctrlreg?p0=AddWeightCtrl
at angular.js:138 at $controller (angular.js:11680) at setupControllers (angular.js:10711) at nodeLinkFn (angular.js:10496) at compositeLinkFn (angular.js:9835) at publicLinkFn (angular.js:9700) at angular.js:1967 at Scope.$eval (angular.js:19396) at Scope.$apply (angular.js:19495) at bootstrapApply (angular.js:1965) (anonymous) @ angular.js:15570 (anonymous) @ angular.js:11849 $apply @ angular.js:19500 bootstrapApply @ angular.js:1965 invoke @ angular.js:5143 doBootstrap @ angular.js:1963 bootstrap @ angular.js:1983 angularInit @ angular.js:1868 (anonymous) @ angular.js:36426 trigger @ angular.js:3522
The code snippet for opening the modal looks like this...
export function openAddWeightModal(data: AddWeightCtrlParameters,
$modal: mm.foundation.modal): angular.IPromise<apsCommands.addWeight> {
return $modal.open({
template: template,
controller: 'AddWeightCtrl as vm',
resolve: {
params: () => data
}
}).result;
}
I've structured the controller and module declaration as follows...
class AddWeightCtrl {
private $modalInstance: mm.foundation.modalInstance;
form: angular.IFormController;
constructor(
$modalInstance: mm.foundation.modalInstance,
$q: angular.IQService,
params: AddWeightCtrlParameters,
$stateParams: StateParams,)
{
this.$modalInstance = $modalInstance;
}
submit() {
}
cancel() {
this.$modalInstance.close();
}
private updateStatus() {
}
pass() {
}
fail() {
}
notApplicable() {
}
}
export default angular.module('aps.controller.AddWeight', requires)
.controller('AddWeightCtrl', AddWeightCtrl)
.name;
This approach has worked without any issues elsewhere in our application, but I can't seem to figure out what's causing the error in this particular case. Any advice or suggestions would be greatly appreciated.