Skip to content

Instantly share code, notes, and snippets.

@jwieringa
Created June 17, 2013 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwieringa/5797967 to your computer and use it in GitHub Desktop.
Save jwieringa/5797967 to your computer and use it in GitHub Desktop.
An example of a directive that reads and writes to scope.
laiApp.directive('demoGreet', function( $parse ) {
return {
link: function linkFn(scope, element, attrs) {
console.log('linkingFn(', scope, element, attrs, ')');
// read out of the scope
scope.$watch( attrs.demoGreet, function ( data ) {
element.text('Hello ' + data.name + '!' );
}, true);
element.bind( 'click', function() {
console.log( 'click', Error().stack );
// write to scope using apply and parse
scope.$apply( function () {
$parse( attrs.demoGreet).assign(scope, 'abc');
});
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment