Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
    
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>JS Bin</title>
  </head>
  <body ng-app="app">
    <div ng-controller="MainCtrl as ctrl">
      <setup-itemized value="ctrl.value">
        <input type="text" ng-model="ctrl.value">
      </setup-itemized>
    </div>
  </body>
</html>
 
angular
    .module('app', [])
    .controller('MainCtrl', function() {
        vm = this;
        console.log('Loading MainCtrl and assign 1 to variable value');
        vm.value = 1;
    })
    .directive('setupItemized', function() {
        return {
            restrict: 'E',
            transclude: true,
            scope: {},
            bindToController: {
              value: '='
            },
            controller: function($scope) {
                vm = this;
                console.log('Loading Directive Controller and assign 10 to variable value');
                vm.value = 10;
              
                $scope.$watch('si.value', function(newVal) {
                  console.log('New value for variable!');
                });
            },
            controllerAs: 'si',
            template: '<h1>Setup Itemized</h1>' +
                    '<p>This is yuor custom directive with transclude!</p>' +
                    '<ng-transclude></ng-transclude>'
        };
    });
Output

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

Dismiss x
public
Bin info
eliagentilipro
0viewers