Last active
August 29, 2015 14:08
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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