2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

Getting exception Error: [$injector:unpr] after create my war file and deployed in server

I have written a simple code to open a modal using angularjs and bootstrap plugin and i am creating a war file using pom.xml

code snippet:

var app = angular.module('apps', [ 'ui.bootstrap' ]);

app.controller('ModalCtrl', [ '$scope', '$uibModal',
		function($scope, $uibModal) {
			$scope.open = function() {
				var modalInstance = $uibModal.open({
					templateUrl : 'testModal.html',
					controller : 'MController',
					size : 'md', // u can define the size like - sm, lg, md
				});
			}
		} ]);

app.controller('MController',
		function($scope, $uibModalInstance) {
			$scope.ok = function() {
				$uibModalInstance.close($ctrl.selected.item);
			};
			$scope.close = function() {
				$uibModalInstance.dismiss('cancel');
			};
		});

Not getting what is the issue as i can see all looks good. And i am keep getting exception on browser console like Error: [$injector:unpr]

userimage

I feel the code looks good but it might happened in case at build time you are minifying the javascript file. If so please change the code as below:


var app = angular.module('apps', [ 'ui.bootstrap' ]);

app.controller('LoginUserModalCtrl', [ '$scope', '$uibModal',
		function($scope, $uibModal) {
			$scope.open = function() {
				var modalInstance = $uibModal.open({
					templateUrl : 'testModal.html',
					controller : 'MController',
					size : 'md', // u can define the size like - sm, lg, md
				});
			}
		} ]);

app.controller('MController', [ '$scope', '$uibModalInstance',
		function($scope, $uibModalInstance) {
			$scope.ok = function() {
				$uibModalInstance.close($ctrl.selected.item);
			};
			$scope.close = function() {
				$uibModalInstance.dismiss('cancel');
			};
		} ]);
Answer is