I am trying to achieve Controller inheritance in Angularjs and followed several articles and examples and couldnot make it work.
I have common functionality across 2 controllers and i have created BaseController for common functionalities and ChildControllers extended this controller.
HTMl file
<div ng-controller="ChildCtrl1">
<div>Gettting absolute url from parent: <strong>{{commonVar}}</strong></div>
<button class="btn btn-primary pull-left" ng-click="scopeChildMethod1 ()">OK</button>
</div>
BaseCtrl.js
var dependencies = [];
define( dependencies, function()
{
function BaseCtrl($scope,$location) {
$scope.commonVar = 42;
$scope.commonMethod1 = function () {
alert('test');
};
};
BaseCtrl.prototype.commonMethod2 = function () {
alert('test2');
};
return BaseCtrl;
});
ChidlCtrl1.js
var dependencies = [ './module','./BaseCtrl'];
define(dependencies, function (module,BaseCtrl) {
return module.controller('ChildCtrl1', function ($scope,$location){
var ChildCtrl1=function($scope, $location) {
BaseCtrl.call(this, $scope, $location);
$scope.scopeChildMethod1 = function () {
alert('test');
};
}
ChildCtrl1.prototype = new BaseCtrl($scope, $location);
ChildCtrl1.prototype.childMethod2 = function () {
alert('test');
};
return ChildCtrl1;
});
});
I see that child scope method is not triggered on button click??where as i can trigger the scope method in BaseController.I am not sure whats wrong in the above code as in why i cannot trigger child methods???
Any help will be appreciated.