繁体   English   中英

角材料mdSelect中的动态标签

[英]Dynamic Labels in Angular Material mdSelect

我对角材有疑问。 我想将Angular Material md-select指令与label动态文本一起使用。 它接缝的是它们的指令创建了html label文本的副本,并放入其span因此,在范围值更新后,它正在更新隐藏label值,而不是在其span (在打开和关闭选择列表后更新中)。 是错误还是我做错了什么? 如果是错误,是否有人发现解决此问题的好方法?

提前致谢!

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>

Plunker

编辑

要查看我的意思是跨度,请检查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开关将其打开和关闭。

希望这可以帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM