Dies ist eine einfache Frage, aber ich kann nicht sämtliche Dokumente zu finden scheinen ...Kann eine Winkelrichtlinie einen eigenen Controller erfordern?
Ich versuche, wenn eine Winkel Richtlinie sowohl als auch eine übergeordnete Steuerung übernehmen kann, um herauszufinden, wie seine eigene. Betrachten Sie die folgenden Beispiele:
Einfache Vererbung von Selbst
app.directive('screen', function() {
return {
scope: true,
controller: function() {
this.doSomething = function() {
};
},
link: function($scope, el, attrs, ctrl) {
// ctrl now contains `doSomething`
}
}
});
Vererbung von Eltern
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
}
}
});
Es gibt sogar Mehrfachvererbung ...
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`
}
}
});
Was ich nicht herausfinden kann ist, wie man eine Direktive erben kann, die sowohl einen übergeordneten Controller als auch einen eigenen erbt. Wie so:
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
}
}
});
Ist das möglich/die richtige Form (oder ist es eine Art von anti-Muster Ich bin nicht bewusst)?
das ist die Art, wie ich es jetzt tue, ... meine SO ein ‚elegant‘ Suche hat gehofft, Verfahren zu offenbaren . Ich denke, das ist genau, wie es gemacht wird =/ – Roi
Ich bin so froh, dass Sie diese Frage gestellt haben, ich hatte eine Menge Zeit damit, es herauszufinden. – richbai90
Warum brauchen Sie^um die Bildschirm-Anweisung zu verlangen? – Winnemucca