【问题标题】:How to use textarea and other elements inside materialize md-container?如何在物化 md-container 中使用 textarea 和其他元素?
【发布时间】:2017-05-15 18:11:11
【问题描述】:

我有readonly 我想在该字段中显示的电子邮件列表,因此我尝试在md-input-container 中使用textarea 使用angularjs ng-repeat,但它会引发错误only one input allowed in the md-input-container。我是新手,不知道使用 AngularMaterial Ui 实现这种方法的更好方法是什么?

main.html

<div layout="row" layout-margin style="height:100px; overflow: scroll;">
    <md-input-container flex="100">
        <div><label>Bcc</label></div>
        <textarea flex="100" ng-repeat="email in notifyCtrl.bcc" name="email" readonly="true">
                </textarea>
    </md-input-container>
</div>

ctrl.js

$scope.notifyCtrl.bcc = ["abc@domain.com","xyz@domain.com"]

【问题讨论】:

    标签: javascript angularjs angular-material materialize


    【解决方案1】:

    由于您需要在一个字段中显示多封电子邮件,我建议使用 &lt;md-chips&gt; 而不是 textarea

    <div layout layout-sm="column" layout-margin >
                    <md-chips flex ng-model="notifCtrl.bcc" class="md-primary" readonly="true" placeholder="Bcc" delete-button-label="Remove Tag" delete-hint="Press delete to remove tag" secondary-placeholder="Bcc">
                    </md-chips> 
     </div> 
    

    【讨论】:

    • 如果有大量数据,你如何让md-chips滚动?
    • 芯片没有滚动它会动态增加高度。您可以将最大高度设置为芯片容器并为其添加滚动
    • 我没有在md-chips 字段中看到使用您的答案的数据
    • 我们是在md-input-container 中使用你的答案还是我们不需要容器?
    • 不是在 md-input-container 里面,它是父 div 什么的
    【解决方案2】:

    如果适合您的需要,您可以从 Angular Material UI 尝试虚拟重复:

    HTML:

         <md-content layout="column">
             <md-virtual-repeat-container id="vertical-container">
                <div md-virtual-repeat="email in notifyCtrl.bcc" class="repeated-item" flex="">
                  {{email}}
                </div>
            </md-virtual-repeat-container>
          </md-content>
    
        </div>
    

    CSS:

    .virtualRepeatdemoVerticalUsage #vertical-container {
      height: 292px;
      width: 100%;
      max-width: 400px; }
    
    .virtualRepeatdemoVerticalUsage .repeated-item {
      border-bottom: 1px solid #ddd;
      box-sizing: border-box;
      height: 40px;
      padding-top: 10px; }
    
    .virtualRepeatdemoVerticalUsage md-content {
      margin: 16px; }
    
    .virtualRepeatdemoVerticalUsage md-virtual-repeat-container {
      border: solid 1px grey; }
    
    .virtualRepeatdemoVerticalUsage .md-virtual-repeat-container .md-virtual-repeat-offsetter div {
      padding-left: 16px; }
    

    JS:

    (function () {
      'use strict';
    
        angular
          .module('app',['ngMaterial'])
          .controller('AppCtrl', function($scope) {
          $scope.notifyCtrl = {};
          $scope.notifyCtrl.bcc = ['abc@domain.com','xyz@domain.com'];  
    });
    })();
    

    在此处附加一个工作代码笔:https://codepen.io/anon/pen/JNBjLx

    来源: https://material.angularjs.org/latest/demo/virtualRepeat

    【讨论】:

    • 我已经修改了我的代码并在这里添加了一个工作代码笔
    猜你喜欢
    • 2017-10-14
    • 1970-01-01
    • 1970-01-01
    • 2016-12-19
    • 1970-01-01
    • 1970-01-01
    • 2014-12-13
    • 2017-11-19
    • 2013-09-24
    相关资源
    最近更新 更多