rendering a dynamic placeholder with angular

后端 未结 2 1533
暖寄归人
暖寄归人 2021-01-14 00:19

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

2条回答
  •  甜味超标
    2021-01-14 01:00

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

    
    

    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;
          });
        }
      }
    });
    

提交回复
热议问题