I am trying to keep my angular project as modular as possible. I currently have 3 nested directives that form the base of my project.
The lower most directive will always have the same core functionality and scope objects, but will need additional scope objects and functions depending on the use case. The app is very large so keeping everything as decoupled as possible is important, as well as following the DRY principle.
In python style OOP I would just inherit all the properties and functions then add to them. Is there something similar in Angular?
For Example:
The base
myApp.directive('itemOption', function () {
return {
restrict: 'E',
templateUrl: "item_option.html",
scope: {
'lowest': '=',
'middle': '=',
'high': '=',
'ngModel': '=',
},
controller: function ($scope) {
$scope.prop1 = "Default 1"
$scope.prop2 = "Default 2"
}
}
}
A repetitive directive that would be used instead of the base
myApp.directive('itemOptionVariation1', function () {
return {
restrict: 'E',
templateUrl: "item_option.html",
scope: {
'lowest': '=',
'middle': '=',
'high': '=',
'ngModel': '=',
},
controller: function ($scope) {
$scope.prop1 = "Default 1"
$scope.prop2 = "Default 2"
// Unique to this directive
$scope.prop900 = "Penguins"
}
}
}
And Another
myApp.directive('itemOptionVariation2', function () {
return {
restrict: 'E',
templateUrl: "item_option.html",
scope: {
'lowest': '=',
'middle': '=',
'high': '=',
'ngModel': '=',
},
controller: function ($scope) {
$scope.prop1 = "Default 1"
$scope.prop2 = "Default 2"
// Unique to this directive
$scope.prop3 = "This is awesome"
}
}
}