I'm trying to get a value from a function inside a function:
Controller
$scope.vm = {};
function myFunc(){
$scope.vm.hello = 'Hello';
function myFunction(){
$scope.vm.world = 'world';
}
}
myFunc();
View
<p>{{vm.hello}} {{vm.world}}</p>
How can I get this to display "Hello world"?
I assume that you are trying to achieve something called 'closure'. If so, modify your controller to:
In your code, the inner function
myFunction()
cannot be called outside themyFunc()
method, because its scope is bounded by this outer method. You can of course call it directly inside outer method, or better - make the inner function immediate: