I have the following code:
var app = angular.module('plunker', []);
app.controller('ParentCtrl', function($scope) {
$scope.name1 = 'Parent';
this.name1 = 'Parent';
});
app.controller('ChildCtrl', function($scope) {
$scope.name1 = 'Child';
this.name1 = 'Child';
this.option = {};
this.option.abc = 25;
foo = function(){
alert(this.option)
};
foo();
});
When I try to access the "this" before the function it is available. When I try to access the this inside of the function then it's undefined. Can someone tell me is there an "AngularJS" way to resolve this?
foo.call(this);. Usually the context in functions will bewindowornullif you are using strict mode.