You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用$uibModal调用独立控制器弹窗报错:roleController未注册

Fixing "The controller with the name 'roleController' is not registered" in $uibModal

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.js loads 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 controllerUrl from 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 06:57:43