2016-04-04 21 views
0

私はAngularの初心者ですので、あくまでも間違いがあれば謝ります。私は角度でディレクティブを通じてのTextFieldの入力を定義した:プレースホルダはテキストフィールドの入力には対応していません

.directive('textField', function() { 
    return { 
     restrict: 'E', 
     scope: true, 
     require: 'ngModel', 
     template: '{{start}}<span class="text-field-cursor">{{end}}</span>', 
     controller: 'TextFieldController', 
     link: function (scope, elem, attrs, ngModel) { 
      scope.keyboardOptions.limitTo = parseInt(attrs.limitTo); 
      scope.keyboardOptions.caps = _.has(attrs, 'caps'); 

      scope.model = ngModel; 

      elem.bind('click', function() { 
       scope.openKeyboard(); 
      }); 

      elem.on('$destroy', function clickDestroyElement() { 
       elem.unbind(); 
      }); 
     } 
    }; 
}) 

その後、私のHTML上で、私はしかし、プレースホルダは、Webページ上で可視化されていない

<text-field class="text-field" data-t-username focusable request-focus="true" ng-class="{ 'is-focused': (focused || active), 'is-active': active }" ng-model="data.username" placeholder='Enter your username here' limit-to="32"></text-field> 

を書きました。私は間違って何をしていますか?

+0

スパンにはプレースホルダがありません。このために入力コントロールを使用する必要があります –

+1

カスタム要素を作成しました。これは入力ではなくなりました。したがって、プレースホルダ属性はありません。これを行うためには、直接指示の中でそれをシミュレートするかもしれませんし、テンプレート上の要素はinput/textareaでなければなりません。 – Bettimms

答えて

1

あなたの指示文では、テンプレートは入力ではありません。したがって、プレースホルダは機能しません。

プレースホルダを使用する入力ディメンションまたはその他のディレクティブにスパンを変更できます。

関連する問題