繁体   English   中英

ng-repeat隐藏除初始元素外的所有元素

[英]ng-repeat hide all elements except initial

在我的页面上,我基于api调用呈现表单。 使用帮助对过滤器,我可以隐藏标题中带有“ id”且等于0的所有元素,但是我需要显示初始元素ID。 我会使用“ $ first”,但第一个元素是复选框值,那么该怎么做呢? 感谢您的帮助。 应用小插曲

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope, $http) {

  $scope.upload = function (){

        $scope.rowKeys = Object.keys($scope.rowData);
        };

  });

app.filter('hide', function () {
  return function(input, arg) {
      return input.replace(arg, '');
  };
})

html

<form style="padding: 15px">
  <button class="btn btn-default" ng-click="upload()">Upload</button>
  <div class="form-group row">
    <div ng-repeat="k in rowKeys | filter: '!id' | filter: '!0'" ng-model="rowValue">
      <label for="rowValue" class="col-sm-2">{{k | hide:'.name'}}:</label>
      <div class=" col-sm-2">
        <input class="form-control rowValue" id="rowValue" value="{{rowData[k]}}" />
      </div>
    </div>
  </div>
  <button type="submit" class="btn btn-default" ng-if="rowData" ng-disabled="!rowValue">Submit</button>
</form>

您可以为此使用ng-if

<div ng-repeat="thing in things">
    <div ng-if="(thing === 'id' || thing.toLowerCase().endsWith('id') === false) ? true : false">
        {{thing}}
    </div>
</div>

暂无
暂无

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

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