Created
June 17, 2013 15:51
-
-
Save jwieringa/5797967 to your computer and use it in GitHub Desktop.
An example of a directive that reads and writes to scope.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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