【发布时间】:2015-09-07 14:51:55
【问题描述】:
我有 2 个控制器,我正在从第一个控制器的功能中调用第二个控制器
$scope.open = function () {
var modal = $modal.open({
templateUrl: 'views/view1.html',
controller: 'controller2',
// other parameters
});
/* some code */
}
两个控制器都在同一个文件夹中。有类似的问题,但我想知道是否有任何方法可以在不使用服务的情况下调用第二个控制器。
编辑 --
这是我得到的错误--
错误:[ng:areq] 参数 'controller2' 不是函数,未定义 http://errors.angularjs.org/1.3.16/ng/areq?p0=controller2&p1=not%20a%20function%2C%20got%20undefined 在 REGEX_STRING_REGEXP (angular.js:63) 在 assertArg (angular.js:1590) 在 assertArgFn (angular.js:1600) 在 angular.js:8502 在 resolveSuccess (ui-bootstrap-tpls.js:2377) 在 processQueue (angular.js:13292) 在 angular.js:13308 在 Scope.$get.Scope.$eval (angular.js:14547) 在 Scope.$get.Scope.$digest (angular.js:14363) 在 Scope.$get.Scope.$apply (angular.js:14652)
【问题讨论】:
-
那么问题出在哪里?找不到控制器
controller2还是什么? -
好的,根据您的错误,这可能是原因:您没有加载控制器脚本。您没有在模块中声明 controller2 ,因此无法访问。可以放控制器定义代码吗?
-
是的,我收到了错误,我没有在 index.html 中包含文件。
标签: angularjs