占位符不处理文本字段输入

时间:2016-04-04 08:51:40

标签: javascript angularjs

我是Angular的新手,所以我提前为任何愚蠢的错误道歉。我已经通过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上,我写了

 <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>

但是,占位符未在网页上可视化。我做错了什么?

1 个答案:

答案 0 :(得分:1)

在您的指令中,模板不是输入。所以占位符无法正常工作。

您可以将span更改为输入或使用占位符的其他指令。

相关问题