How to set ng-controller as an expression from the $scope?
According to the documentation:
ngController – {expression} – Name of a globally accessible constructor function or an expression that on the current scope evaluates to a constructor function.
But how to evaluate scope expression as a controller for controllers that have been registered with module .controller?
For example:
Layout:
<div ng-controller="myExpr"></div>
JavaScript (define controller):
app.controller('myCtrl', ['$scope', '$timeout', function () { ... }];
JavaScript (parent scope):
$scope.myExpr = ...;
What should be in myExpr to use myCtrl as a controller via expression?
I've tried $controller('myCtrl')... not working...
P.S. If controller has been defined via globally accessible function.. it's possible to provide it as myExpr. But what to do if it has been defined so?
app.controller('myCtrl', [...])returns a result that can be assigned to a variable and that could be assigned to the scope expression. That said, I fail to understand why you would want to do such a thing...Error: Argument 'ctrl' is not a function, got ObjectYou could try: jsbin.com/otakaw/8/edit