Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rendering a dynamic placeholder with angular

I've looked around, found several resources labeled 'ng-placeholder' or something incredibly similar. I cannot get this to work:

<input type="text" placeholder="{{option.name}}" class="form-control" ng-switch-when="text" />

I've noticed there doesn't appear to be anything on the input documentation as well. I'm pretty new to angular, and this has done nothing but frustrate me for a few hours. There must be a way to do this.

like image 574
Seiyria Avatar asked Feb 13 '23 11:02

Seiyria


1 Answers

Why not write your own directive for ng-placeholder? Something simple like this should work. You can call it in your html like this

<input ng-placeholder='test'>

Where test is a scope variable in the current controller.

.directive('ngPlaceholder', function($document) {
  return {
    restrict: 'A',
    scope: {
      placeholder: '=ngPlaceholder'
    },
    link: function(scope, elem, attr) {
      scope.$watch('placeholder',function() {
        elem[0].placeholder = scope.placeholder;
      });
    }
  }
});
like image 176
Zack Argyle Avatar answered Feb 16 '23 02:02

Zack Argyle