Skip to content

Instantly share code, notes, and snippets.

@aaronfrost
Last active August 29, 2015 14:02
Show Gist options
  • Save aaronfrost/af7b034ee0ca00662158 to your computer and use it in GitHub Desktop.
Save aaronfrost/af7b034ee0ca00662158 to your computer and use it in GitHub Desktop.
Gist for a watch discussion
angular.module('app').directive('MyDirective', function(){
//NEW AND IMPROVED, NOW WITH LESS WATCHING!
return {
restrict: 'AE',
replace: 'true',
templateUrl: '../../blah.html',
scope:{
item: '='
},
link: function(scope, elem, attrs){
var unwatchItem = scope.$watch('item', function(_new, _old){
if(!_.isUndefined(_new)){
//DO SOMETHING COOL WITH _new ITEM
unwatchItem();
}
})
}
};
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment