Skip to content

Instantly share code, notes, and snippets.

@exit99
Last active August 29, 2015 14:08
Show Gist options
  • Save exit99/379c1dd5507d15ec7977 to your computer and use it in GitHub Desktop.
Save exit99/379c1dd5507d15ec7977 to your computer and use it in GitHub Desktop.
How to make base directive controllers that can be inherited in Angular.js
app.directive('upgrade1', function () {
return {
restrict: 'E',
templateUrl: "my_template.html",
scope: {
'info': '=info',
},
controller: 'upgrade1',
}
});
app.directive('upgrade2', function () {
return {
restrict: 'E',
templateUrl: "my_template.html",
scope: {
'info': '=info',
},
controller: 'upgrade2',
}
});
function baseCtrl ($scope, $rootScope, $timeout) {
$scope.penguins = "Black and White";
$rootScope.tigers = "Black and Orange";
$timeout(function () {
$scope.half_black_animals = $scope.penguins + $rootScope.tigers;
});
}
app.controller('upgrade1', function ($scope, $rootScope, $timeout) {
$injector.invoke(baseCtrl, this, {$scope:$scope, $rootScope:$rootScope, $timeout:$timeout});
});
app.controller('upgrade2', function ($scope, $rootScope, $timeout) {
$injector.invoke(baseCtrl, this, {$scope:$scope, $rootScope:$rootScope, $timeout:$timeout});
$scope.flamingos = "Pink Pink Pink";
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment