【发布时间】:2016-05-15 11:45:50
【问题描述】:
第一次尝试使用ngTransclude做自定义指令,实现浮动标签功能如下图:Floating label pattern — Angular JS,但是不行。
这是我的指令代码:
.directive('floatingLabel', function () {
return {
restrict: 'A',
scope: {
label: '@',
value: '='
},
transclude: true,
templateUrl: 'floating-label-template.html'
}}
)
指令的模板:
<div class="field">
<label ng-show="value" class="show-hide">{{label}}</label>
<div ng-transclude></div>
</div>
我正在尝试通过以下方式使用它:
<input floating-label label="Floating" value="floatingDirective" type="text" class="form-control" ng-model="floatingDirective"/>
Plunker 使用我的代码:https://plnkr.co/edit/MC8G4H3B9zEleaBZ7ijJ?p=preview
附注我正在使用 AngularJS 1.4.9
【问题讨论】:
标签: angularjs angular-directive angularjs-ng-transclude