【发布时间】:2016-11-04 13:12:13
【问题描述】:
我使用了这里的一种风格:http://tympanus.net/Development/TextInputEffects/index.html
要创建输入指令,请参阅 plunker:https://plnkr.co/edit/wELJGgUUoiykcp402u1G?p=preview
这对标准输入字段非常有用,但是,我正在努力使用 Twitter 提前输入:https://github.com/twitter/typeahead.js/
问题 - 我如何使用带有预输入的浮动输入标签?
app.directive('floatInput', function($compile) {
return {
restrict: 'E',
replace: true,
transclude: true,
scope: {
elemTitle: '=elemTitle',
elemtId: '=elemeId'
},
templateUrl: 'input-template.html',
link: function(scope, elem, attrs) {
var ngModelName = elem.attr('input-model');
var inputElem = angular.element(elem[0].querySelector('input'));
inputElem.attr('ng-model', ngModelName);
$compile(inputElem)(scope);
$compile(inputElem)(scope.$parent);
var inputLabel = angular.element(elem[0].querySelector('label span'));
inputLabel.attr('ng-class', '{\'annimate-input\' : '+ngModelName+'.length > 0}');
$compile(inputLabel)(scope);
},
controller: function($scope) {
$scope.title = $scope.elemTitle;
$scope.inputId = $scope.elemId
}
}
})
HTML:
<div>
<span class="input input--juro">
<input class="input__field input__field--juro" type="text" id="{{inputId}}" ng-model="tmp" />
<label class="input__label input__label--juro" for="{{inputId}}">
<span class="input__label-content input__label-content--juro">{{title}}</span>
</label>
</span>
</div>
【问题讨论】:
-
您在代码中哪里引用了
typeahead? -
@JossefHarush - 我还没有,我不知道从哪里开始。
-
请更清楚您有什么问题。你试过什么?您看到错误了吗?
-
@VadiemJanssens - 更新了有问题的帖子。
标签: javascript html angularjs typeahead.js angular-directive