使用$uibModal调用独立控制器弹窗报错:roleController未注册
Hey there! Let's break down why you're hitting this error and how to fix it step by step.
The Root Issue
First off: UI Bootstrap's $uibModal.open() doesn't have a controllerUrl option—that's not a valid parameter. So your app isn't actually loading the separate controller file you specified, which is why Angular can't find roleController when you try to open the modal.
Step-by-Step Fixes
1. Ensure Your Controller File is Properly Loaded
Since you're using RequireJS, you need to make sure the controller module is loaded before you try to use it. A clean approach is to dynamically load the controller right before opening the modal (great for lazy loading):
// Load the controller first, then initialize the modal require(['/App/views/security/people/roleController.js'], function() { var modalInstance = $uibModal.open({ templateUrl: '/App/views/security/people/roleView.html', controller: 'roleController', // Now the controller is registered and ready size: 'lg', resolve: {} }); });
2. Verify Controller Registration
Double-check that your controller is correctly tied to your Angular app module. Your current code looks solid, but confirm the app variable refers to your actual Angular module (the one that includes ui.bootstrap as a dependency):
// First, define your main app module with ui.bootstrap dependency var app = angular.module('yourAppName', ['ui.bootstrap']); // Then your controller (in roleController.js) define(['app'], function (app) { app.controller("roleController", ["$scope", "dataService", "$uibModal", "messageService", function ($scope, dataService, $uibModal, messageService) { // Your controller logic here console.log('Role controller is loaded and ready!'); }]); });
3. Check for Loading Errors
- Open your browser's Network tab and confirm
roleController.jsloads successfully (no 404 errors). - If using RequireJS, verify your path mappings are correct—make sure the path in
require()matches exactly where your controller file lives.
Quick Recap
- Remove the invalid
controllerUrlfrom your modal config. - Load your controller file (via RequireJS) before attempting to open the modal.
- Confirm your controller is properly registered to your Angular app module.
Once you make these changes, your modal should find the controller without throwing that error.
内容的提问来源于stack exchange,提问作者Farzad Karimi

