简体   繁体   English

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

[英]ng-repeat hide all elements except initial

On my page I'm rendering the form based on api call. 在我的页面上,我基于api调用呈现表单。 With help couple filters I'm hiding all elements which have 'id' in title and which equal 0, but I need to display initial element Id. 使用帮助对过滤器,我可以隐藏标题中带有“ id”且等于0的所有元素,但是我需要显示初始元素ID。 I would used '$first' but the first element is checkbox value, so how can it be done? 我会使用“ $ first”,但第一个元素是复选框值,那么该怎么做呢? I appreciate for any help. 感谢您的帮助。 applied plunk 应用小插曲

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 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>

You can make use of ng-if for this: 您可以为此使用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