twoWayBindingWithWatch

trying to get two way binding in directive working with watch

by lesouthern

HTML

<div id="main-window" class="main-window profile">
	<div ng-app="pageModule"
		ng-controller="pageCtrl">
		<input type="text"
			test-directive
			ng-model="test" />
		<input type="button"
			ng-click="test=''"
			value="Click Me" />
	</div>
</div>

JavaScript

var pageModule = angular.module('pageModule',[])
.controller('pageCtrl',function($scope) {
})
.directive('testDirective',function() {
	return {
		restrict : 'A',
		scope : {
			model : '=ngModel'
		},
		link : function($scope,$element,$attrs) {
			$scope.$watch('model',function(x) {
				console.log('this is model: ' + x);
			});
		}
	}
});