Scope Contrller

I want to install a controller whose name is described in the scope of another controller

Js file:

.controller('PageCtrl', [
  '$http',
  '$scope',
  '$routeParams',
  '$location',
  function($http, $scope, $routeParams, $location){
    $scope.CurrentPageCtrl = 'CompaniesCtrl';    
  }])

.controller('CompaniesCtrl', [
  '$http',
  '$scope',
  '$routeParams',
  '$location',
  function($http, $scope, $routeParams, $location){
    console.log('loaded');
  }
])

HTML file:

<ng-controller ng-controller = "PageCtrl">
    <ng-controller ng-controller = "{{CurrentPageCtrl}}">111</ng-controller>
</ng-controller>

But I get:

Error: [ng:areq] Argument '{{CurrentPageCtrl}}' is not a function, got undefined
+4
source share
1 answer

The fact is that the controller will not be called until it is specified in the ng controller in your code. Thus, there is no question that the $ scope variable is available in your view, i.e. Your html. Thus, you must either use ngRouter or ui.router to specify the controller at runtime, or you must use the global directive as indicated in the link response below. The name of the dynamic NG controller

+2

All Articles