Questa è una domanda semplice, ma io non riesco a trovare alcuna documentazione relativa ...Una direttiva angolare può richiedere un proprio controllore?
sto cercando di scoprire se una direttiva angolare può sia erediterà un controller genitore così come la sua propria. Prendere in considerazione i seguenti esempi:
Ereditarietà semplice da self
app.directive('screen', function() {
return {
scope: true,
controller: function() {
this.doSomething = function() {
};
},
link: function($scope, el, attrs, ctrl) {
// ctrl now contains `doSomething`
}
}
});
eredità dal padre
app.directive('screen', function() {
return {
scope: true,
controller: function() {
this.doSomething = function() {
};
}
}
});
app.directive('widget', function() {
return {
scope: true,
require: '^screen',
link: function($scope, el, attrs, ctrl) {
// ctrl now contains `doSomething` -- inherited from the `screen` directive
}
}
});
C'è anche l'ereditarietà multipla ...
app.directive('screen', function() {
return {
scope: true,
controller: function() {
this.doSomething = function() {
};
}
}
});
app.directive('widget', function() {
return {
scope: true,
require: ['^screen','^anotherParent'],
link: function($scope, el, attrs, ctrl) {
// ctrl[0] now contains `doSomething` -- inherited from the `screen` directive
// ctrl[1] now contains the controller inherited from `anotherParent`
}
}
});
Quello che non riesco a capire è come fare in modo che una direttiva erediti sia un controllore genitore che il proprio. In questo modo:
app.directive('screen', function() {
return {
scope: true,
controller: function() {
this.doSomething = function() {
};
}
}
});
app.directive('widget', function() {
return {
scope: true,
require: '^screen',
controller: function($scope) {
// isolated widget controller
},
link: function($scope, el, attrs, ctrl) {
// I need the `screen` controller in ADDITION to the isolated widget controller accessible in the link
}
}
});
È questo possibile forma/corretta (o è una sorta di anti-modello sono a conoscenza di)?
questo è il modo in cui sto facendo ora ... il mio SO ricerca speravo per rivelare un metodo più 'elegante' . Immagino che questo sia esattamente come è stato fatto =/ – Roi
Sono così felice che tu abbia fatto questa domanda, stavo passando un bel pò di tempo a capirlo. – richbai90
Perché è necessario che^richieda la direttiva sullo schermo? – Winnemucca