嘗試使用ngTransclude第一次製作自定義指令,實現浮動標籤功能,如下所示:Floating label pattern — Angular JS,但它不起作用。ngTransclude指令不起作用,無法實現我錯在哪裏
這裏是我的指令代碼:
.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
P.S.我正在使用AngularJS 1.4.9