ng-repeat hide all elements except the first one

Hello there! I'm currently working on rendering a form based on an API call. Using a couple of filters, I am able to hide all elements that have 'id' in the title and which equal 0. However, I do need to display the initial element Id. I thought about using '$first', but since the first element is a checkbox value, I'm not sure how to proceed. Any help would be greatly appreciated. Check out the applied plunk for reference.

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, '');
  };
})

Here's the HTML snippet:

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

Answer №1

To achieve this, you can utilize the ng-if directive like so:

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How are the script name and script file connected in WordPress enqueuing?

When adding a jQuery script to the function.php file using the enqueue method, how does the script name relate to the actual file that contains the jQuery code? Is the script name arbitrary, or is it derived from either the file name or the actual script w ...

Using the `on` method of jQuery to make an Ajax request

I'm facing a challenge with using Jquery to load dynamic wall posts for followers. The issue arises when trying to work with dynamic content in the traditional click method. To solve this, I have implemented the on method for the response. However, I ...

Angular Directive for dragging and dropping elements within an iFrame

Looking for controls to enable Drag & Drop functionality across an iFrame? The reason for needing this capability within an iframe is due to building a CMS where any "absolute" css changes on the editing page will also affect the main site. I have develop ...

Undefined property error

router.post('/:token',(req,res)=>{ let language= req.query.language let name= req.query.name let param =[] if(req.path.length == 5){ param.push({ language: language },{ name: name }) ddp.personConnected(param, function(err, response) { i ...

There was an issue stating that valLists is not defined when paginating table rows with AngularJS and AJAX

I found a helpful code snippet on this website for implementing pagination in AngularJS. I'm trying to adapt it to work with data from a MySQL DB table called 'user', but I keep running into an issue where the valLists variable is undefined, ...

showing console logs before initializing preferences may lead to inaccurate results

My Content Management System (CMS) is WordPress. Recently, after making some changes, I encountered an error on a specific page: An error occurred: loading pref showConsoleLogs before prefs were initialised, leading to incorrect results being displayed - ...

Neglecting to send a socket signal while assigning a variable to a socket message

In my client-side script, I am using the following snippet: socket.on('bla', function(data) { if (data == ID) { console.log('I don't understand what's happening here.'); } }) socket.on(ID, function(data) { ...

Guide on entering text into a concealed text box using WebDriver and Java

When attempting to use sendkeys on an input field, I encountered a warning that puzzled me: org.openqa.selenium.InvalidElementStateException: Element must not be hidden, disabled or read-only (WARNING: The server did not provide any stacktrace informati ...

Substitute "Basic Authentication" with "Form Authentication"

Is there a way in W20 to switch from using "Basic Authentication" to "Form Authentication"? The current documentation mentions only the use of "basicAuth" and does not provide information on implementing form authentication. Our app is built with Angular ...

Using a promise inside an Angular custom filter

I am attempting to implement a filter that will provide either a success or error response from the ret() function. The current code is returning {}, which I believe is its promise. .filter('postcode', ['$cordovaSQLite', '$q' ...

Experiencing issues in retrieving data post-login using ASP.net session key method

I have developed a website using AngularJS for the front-end and Windows webforms for the back-end. I believe that the Authorization process is carried out using ASP.net Session Key. The approach involves creating an AngularJS Post method for "login" foll ...

Troubleshooting: React is not defined in Rollup + React 17 with updated JSX Transform

I'm currently working on prototyping a microfrontend architecture using Rollup and multiple create-react-app applications. However, when I try to locally yarn link my external app with the container app, I am encountering the following error: The err ...

Experienced an unexpected setback with the absence of the right-click capability on a Javascript-powered hyperlink, specialized for

I am facing an issue with a hyperlink on my website. This particular hyperlink submits a hidden form using the POST method to redirect users to another site. However, when someone right-clicks on this hyperlink and tries to open it in a new tab, they are o ...

Parsing the JSON string from PHP using JSON.parse resulted in an unexpected and strange array

I've encountered a challenge when trying to transfer a JSON object from the server to client-side JavaScript. I fetched rows of data from a MySQL query and stored them in $result. Below is the code snippet: var json = '<?= json_encode($resu ...

Creating a dynamic number of datasets in Chart JSWith Chart JS

After extensive searching, I thought I was on the verge of finding a solution several times, but unfortunately, no luck! I am aware that a similar question was posted yesterday: React Chartjs, how to handle a dynamic number of datasets, but it remains una ...

Can VueJS lifecycle hooks be outsourced?

Is it possible to organize lifecycle hooks (like created / mounted) in a separate file for better simplicity and cleanliness? MyGreatView.vue import created from 'created.js' export default { created, // created() { console.log('vue Cre ...

Object.assign versus the assignment operator (i.e. =) when working with React components

Just a quick question: I've come across some answers like this one discussing the variances between Object.assign and the assignment operator (i.e. =) and grasp all the points made such as object copying versus address assignment. I'm trying to ...

Recursively converting trees in JS/ES6

Currently, I am attempting to convert a tree structure provided in the following format: {"Parent": { "Child1": ["toy1"], "Child2": { "Nephew": ["toy2", "toy3"] } } } into a standardized tree form ...

Nested AngularJS Directives

Two of my directives are called resource and formajax. Let's take a look at their implementations: Resource resource.coffee (snippet) (...) ($http, $location, $compile) -> restrict: "E" templateUrl: templateUrl sc ...

Achieving dynamic population of a second dropdown menu based on selection from the first dropdown menu using PHP

In my current project, I am faced with the task of populating three different menus. The first menu is generated using a MySQL query in PHP and displays TV shows like "Modern Family" or "Dexter". What I want to achieve is that once a TV show is selected fr ...