Skip to content

Instantly share code, notes, and snippets.

@whisher
Created November 25, 2014 08:59
Show Gist options
  • Save whisher/cf4ac38951f32bdcc59b to your computer and use it in GitHub Desktop.
Save whisher/cf4ac38951f32bdcc59b to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<title>Directives</title>
</head>
<body>
<div ng-controller="ChildController as child">
<button type="button" ng-click="child.sayMe()">Say me!</button>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.1/angular.min.js"></script>
<script>
var app = angular.module('myApp', [])
app.controller('BaseController',function() {
this.me = 'Base';
this.sayMe= function() {
alert(this.me);
}
});
app.controller('ChildController', function($scope, $controller) {
var controller = $controller('BaseController as base', {$scope: $scope});
angular.extend(this, controller);
this.me = 'Child';
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment