// Create an application module for our demo.
angular.module("demo", []);
// --------------------------------------------------------------------------- //
// --------------------------------------------------------------------------- //
// *** NOTE: We are defining the first module with one component ***
class Ctrl1 {
constructor() {
this.description = "I'm the FIRST component";
}
}
let Component1 = {
controller: Ctrl1,
template: "<div style='background-color: green;color: white;'>{{ $ctrl.description }}</div>"
};
let mod1 = angular.module("mod1", [])
.component("selector", Component1)
.name;
// --------------------------------------------------------------------------- //
// --------------------------------------------------------------------------- //
// *** NOTE: We are defining the second module with one component on the same selector ***
class Ctrl2 extends Ctrl1 {
constructor() {
super();
this.description = "I'm the SECOND component";
}
}
let Component2 = {
controller: Ctrl2,
template: "<div style='background-color: red;color: white;'>{{ $ctrl.description }}</div>"
};
let mod2 = angular.module("mod2", [])
.component("selector", Component2)
.decorator("selectorDirective", ($delegate) => {
// CAUTION: Because I am using the .decorator() module method, this call has
// to come AFTER the value that it is decorating. This is different than the
// .config() block, which can be invoked at any point in the module definition.
// --
console.log(". . . . . . . . . . . . . . . . .");
console.log("There are %s matching components ", $delegate.length);
console.log("Selecting the latest one.");
console.log(". . . . . . . . . . . . . . . . .");
let index = $delegate.length - 1;
let returnComponent = $delegate[index];
// Return a new array that contains only the latest-selected version
// of the component.
return [returnComponent];
})
.name;
//...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.