Angular: Directive Parent Scope Value Binding Example
http://angularjs.org/
by Matthew Marcus
HTML
<div ng-controller="MyCtrl">
Hello, {{values.something}}!
<div my-directive="values.something">
<span>{{ values.something }}</span>
</div>
</div>
JavaScript
var myApp = angular.module('myApp',[]);
myApp.directive('myDirective', function() {
return {
restrict: 'A',
scope: {
localSomething: '=myDirective'
},
link: function(scope, elem, attrs){
scope.$watch('localSomething', function(newVal){
console.log(newVal);
});
}
};
});
//myApp.factory('myService', function() {});
function MyCtrl($scope, $timeout) {
$scope.values = null;
$timeout(function(){
$scope.values = {something: 'SomeValue'};
}, 1000);
}