我有角度材料的问题。我想在md-select
中使用Angular Material label
指令和动态文本。它接缝他们的指令创建html label
文本的副本并放入其span
所以在更新范围值后,它更新隐藏的label
中的值,但不在他们的span
中更新(它在打开和关闭选择列表后更新)。这是一个错误还是我做错了什么?如果它是一个bug,有人看到一个很好的方法来修复它吗?
提前致谢!
JS:
angular.module('myApp', ['ngMaterial'])
.controller('MyController', function ($scope, $timeout) {
$timeout(function(){
$scope['select_n_letter'] = 'Lorem ipsum';
}, 500);
})
;
;
HTML:
<body ng-app="myApp">
<div ng-controller="MyController" style="padding-top: 50px">
<form name="a_form">
<md-input-container>
<label>{{select_n_letter}}</label>
<md-select
required
name="letter"
ng-model="letter"
>
<md-option value="option">selected</md-option>
</md-select>
</md-input-container>
</form>
</div>
编辑
要查看我的意思,请查看Plumker预览并查看编译指令HTML,如下所示:
<md-select required="" name="letter" ng-model="letter" class="ng-pristine md-default-theme ng-invalid ng-invalid-required ng-touched" tabindex="0" aria-disabled="false" role="combobox" aria-expanded="false" id="select_3" aria-required="true" aria-invalid="true">
<md-select-value class="md-select-value md-select-placeholder" id="select_value_label_0">
<span>/* text should goes here */</span>
<span class="md-select-icon" aria-hidden="true"></span>
</md-select-value>
</md-select>
一种可能的解决方案是显示两个相同的md-select(除了它们的标签)。并使用ng-show在它们之间切换。另一种可能性,使用包含md-select的指令。使用ng-if以不同的标签作为输入来打开和关闭它。
希望这可以帮助