KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
So first day on the job with angularjs and i'm not quite getting it. I'm trying to mimic an html5 placeholder using an angular directive. It totally works until I add an ng-model to the field and then it only works after a user interacts with the field and also breaks any value the field had. code up here http://jsbin.com/esujax/32/edit the directive App.directive('placehold', function(){ return { restrict: 'A', link: function(scope, element, attrs) { var insert = function() { element.val(attrs.placehold); }; element.bind('blur', function(){ if(element.val() === '') insert(); }); element.bind('focus', function(){ if(element.val() === attrs.placehold) element.val(''); }); if(element.val() === '') insert(); } } }); the html <textarea ng-model="comment" placehold="with a model it doesn't work"></textarea> seems super simple but i'm lost
Tags (comma-separated)
Save Edits
Cancel