<div ng-controller="BMWController">
    My name is {{ name }} and I am a {{ type }}
    <button ng-click="clickme()">Click Me</button> 
</div>
function CarController($scope) {

    $scope.name = 'Car';
    $scope.type = 'Car';
    
    $scope.clickme = function() {
        alert('This is parent controller "CarController" calling');
    }
}
  
function BMWController($scope, $injector) {

    $injector.invoke(CarController, this, {$scope: $scope});
    
    $scope.name = 'BMW';  
}

Теги: javascript, angularjs, сниппет

Редактировать