Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Get parent controller in child controller which all use 'controller as vm' notation" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
  <style>
        input {
            display: block;
        }
        .parent {
            padding: 4px;
            border: blue solid 1px;
        }
        .child {
            border: red solid 1px;
        }
    </style>
</head>
<body data-ng-app="app">
  <section class="parent" 
           data-ng-controller="parentCtrl as vm">
    <input data-ng-model="vm.name">
    
    <!-- have to change the prefix after the 'as' not to have conflict -->
    <section class="child"
             data-ng-controller="childCtrl as vmc">
      <input data-ng-model="vm.name">
      <!-- same results -->
      <input data-ng-model="$parent.vm.name">
      <!-- same results -->
      <input data-ng-model="vmc.parent.name">
      <!-- same results -->
      <button data-ng-click="vmc.changeName()">Change name</button>
    </section>
  </section>
</body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
julianpaulozzipro
0viewers