Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
</head>
<body ng-app="myApp">
  <div ng-controller="CtrlOne">
    <div ng-controller="NestedController">
      Hello, {{name}}
      <namer></namer>
    <reset></reset>
    </div>
    
  </div>
  <script>
    var myApp = angular.module("myApp", []);
    myApp.controller("CtrlOne", function ($scope, $rootScope) {
      $scope.name = "Name";
      $rootScope.$on('ResetName', function() {
        $scope.name = "Name"
      });
    });
    myApp.controller("NestedController", function ($scope) {
      if ($scope.name === "Name") {
        $scope.name = "Not Your Name";
      }
    });
    myApp.directive("namer", function() {
      return {
        restrict: 'EAC',
        template: '<input type="text" ng-model="name"></input>',
        link: function($scope, element, attrs, controller) {
        }
      };
    });
    myApp.directive('reset', function () {
      return {
        restric: 'E',
        template: '<input type="button" ng-click="reset()" value="Reset"></input>',
        link: function ($scope, element, attrs, controller) {
          $scope.reset = function() {
            $rootScope.$emit('ResetName');
          }
        }
      }
    })
  </script>
</body>
</html>
Output

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

Dismiss x
public
Bin info
anonymouspro
0viewers