Angular: Empty Fiddle

http://angularjs.org/

by Pratik Bhattachary

HTML

<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-controller="MyCtrl">
  <myp-directive myarg="myObject"></myp-directive>
</div>

JavaScript

var myApp = angular.module('myApp', []);

//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});

function MyCtrl($scope) {
  $scope.name = 'Superhero';
}

myApp.directive('mypDirective', function() {
  return {
    restrict: 'E',
    scope: {
      myarg: '='
    },
    controller: 'DirectiveCtrl',
    controllerAs: 'directiveCtrl',
    bindToController: true,
    template: '{{data}} - {{pred}}',
    link: function(scope, elem, attr, directiveCtrl) {
      scope.data = "Hello"
    }
  };
});

myApp.controller('DirectiveCtrl', function($scope) {
  var self = this;
	self.prediction = "1";
  $scope.$watch(function() {
    return self.prediction;
  }, function(newVal, oldVal) {
    if (newVal !== oldVal && newVal !== null) {
      var text = "SomeText";
			scope.data = text
    }
  });
});