我是 Angular 的新手,所以对于任何愚蠢的错误我提前表示歉意。我已经通过 Angular 中的指令定义了一个文本字段输入:
.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 上,我写了
<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>
但是,占位符并未在网页上显示。我做错了什么?
最佳答案
在您的指令中,模板不是输入。所以占位符不起作用。
您可以将范围更改为输入或其他使用占位符的指令。
关于javascript - 占位符不适用于文本字段输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36398203/