这可能很做作,但这似乎是你想要的:
angular.module('app', []);
(function () {
'use strict';
angular
.module('app')
.controller('ParentController', ParentController);
function ParentController() {
var vm = this;
vm.hello = "Hello from Parent Controller!";
vm.helloAgain = function() {
return "Hello again from Parent Controller";
}
vm.helloYetAgain = function() {
return "Hello AGAIN from Parent Controller";
}
}
})();
(function () {
'use strict';
angular
.module('app')
.controller('ChildController', ['$controller', ChildController]);
function ChildController ($controller) {
var vm = this;
var parent = $controller('ParentController');
parent.constructor.apply(this, arguments);
vm.hello = "Hello from Child Controller!";
vm.helloAgain = function() {
return parent.helloAgain.call(this);
}
}
})();
<body ng-app="app">
<div ng-controller="ParentController as parent">
<h4>{{ parent.hello }}</h4>
<div ng-controller="ChildController as child">
<h4>{{ child.hello }}</h4>
<h4>{{ parent.hello }}</h4>
<!-- calls parent.helloAgain() from app.childController.js -->
<h1>{{ child.helloAgain() }}</h1>
<h1>{{ child.helloYetAgain() }}</h1>
</div>
</div>
</body>
注意,它不是真正的原型继承。