我有一个观点如下:
<html ng-app="app" ng-controller="mainController">[...]
<body ng-controller="currentController">[...]
我希望能够从上层控制器(mainController)的变量($ scope.currentController)设置主体控制器。控制器mainController
如下所示:
angular.module("app").controller("mainController", function($scope) {
$scope.currentController = "indexController"; // 'indexController' being the name of the controller I want to apply to the view
});
这显然不起作用,如何从JS动态设置控制器到视图?
编辑:(致@mrhobo回答)
我试过这个,假设我每个控制器都有一个文件:
angular.module("app").controller("mainController", function($scope, indexController) {
$scope.currentController = indexController;
});
我收到此错误:Doc Angular error
答案 0 :(得分:1)