Ways to display the hidden element using AngularJS

I want to show the information of "[6] Peter who is 95 years old" in a hidden text box, which should only appear when the button

<button ng-click="show_id(friend.id)">get my id</button>
is clicked. The name should be displayed using the ng-model="name", and age with ng-model="age".

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8>
  <title>Example - example-example42-production</title>

  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.1/angular.min.js"></script>

<script>
angular.module("my_app",[])
.controller("my_ctr",function($scope){

    $scope.show_id=function(index){
        alert(index);
    }
})
</script>
</head>
<body ng-app="my_app" ng-controller="my_ctr">
    <div ng-init="friends = [
    {id:1, name:'John', age:25, gender:'boy'},
    {id:2, name:'Jessie', age:30, gender:'girl'},
    {id:3, name:'Johanna', age:28, gender:'girl'},
    {id:4, name:'Joy', age:15, gender:'girl'},
    {id:5, name:'Mary', age:28, gender:'girl'},
    {id:6, name:'Peter', age:95, gender:'boy'},
    {id:7, name:'Sebastian', age:50, gender:'boy'},
  ]">
    I have {{friends.length}} friends. They are:

    <ul>
      <li  ng-repeat="friend in friends.slice().reverse()">
        [{{friend.id}}] {{friend.name}} who is {{friend.age}} years old.
        <input type="text" ng-model="name" ng-hide="true">
          <input type="text" ng-model="age" ng-hide="true">
          <input type="text" ng-model="gender" ng-hide="true">
        <button ng-click="show_id(friend.id)">get my id</button>
      </li>

    </ul>
  </div>
</body>
</html>

Unfortunately, this code is currently not functioning as intended.

Answer №1

Here is a solution you can try:

  <li  ng-repeat="friend in friends.slice().reverse() ">
    [{{friend.id}}] {{friend.name}} who is {{friend.age}} years old.
    <input type="text" ng-model="friend.name" ng-show="showItem">
      <input type="text" ng-model="friend.age" ng-show="showItem">
      <input type="text" ng-model="friend.gender" ng-show="showItem">
    <button ng-click="showItem=true">get my id</button>       
  </li>

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

Ways to resolve the issue of undefined $route.current in AngularJS

I have recently started using AngularJS and I am encountering an error "TypeError: $route.current is undefined". Please refer to the code snippet below: var sampleApp = angular.module('sampleApp', ['ngRoute']); sampleApp.config([&ap ...

Reactjs - There was an error: $node.attr(...).tooltip is not defined

I am currently troubleshooting the SummerNote mention library and encountering an issue - Uncaught TypeError: $node.attr(...).tooltip is not a function The versions I am using are: - "react-summernote": "^2.0.0", - React version: "react": "^16.8.6", ...

Featuring data utilizing Ajax JSON in CodeIgniter

How can I display the data using AJAX? After making the data call to the controller, the JSON data is available but the data for "name", "address", and "telp" based on the "id_data" is not showing up. How can I display this data? Views <input id="id_d ...

Firebase ref.on('value') will repeatedly trigger, even if no changes have occurred

My current setup involves using an event listener to monitor changes in my real-time database. const [chats, setChats] = useState({}); const ref = db.ref(`users/${sender}/chat/`); ref.on('value', (snapshot) => { const data = snapshot ...

Vue JS - Troubleshooting Checkbox Validation Error During Form Submission

When a user fills out my registration form, there is a checkbox to confirm acceptance of the terms and conditions. Currently, the validation error for this checkbox appears immediately upon hitting submit, even though the checkbox starts as unchecked. The ...

The function getElementbyId is not recognized

My JavaScript code is supposed to change the color of a button, but I'm running into an issue where it says that getting the button is not a function. Strangely enough, the same function (with the same capitalization and case) works perfectly just a f ...

Express-Session Object Method

I am currently facing an issue with linking an object to an Express session. Below is the code I am using: var express = require('express'); var session = require('express-session'); // Defining an object named "engine" which simulate ...

send a message to all clients using socket.io

I am having trouble figuring out how to broadcast a message from the client or another NodeJS file to all clients. While I was able to send messages to the server successfully, I am not able to reach every other client. Server code: var io = require(&ap ...

The Typescript compiler is unable to locate the module './lib'

I'm currently integrating the winston-aws-cloudwatch library into my TypeScript server-side application. If you want to replicate the issue, I have provided a SSCCE setup on GitHub. Here are the details: index.ts import logger from './logger& ...

Having difficulty in running unit tests in Karma and Webstorm 8

I'm having trouble running Karma unit tests in WebStorm 8 using my Karma configuration file: module.exports = function (config) { config.set({ // base path, used to resolve files and exclude basePath: '', // frameworks to use ...

Timer for searching webpages using Javascript

I am looking for a way to continuously search a specific webpage for a certain set of characters, even as the text on the page changes. I would like the program to refresh and search every minute without having to keep the webpage open. In addition, once ...

Mastering the art of using either promises or callbacks properly

Attempting to retrieve the result of a variable after completing all asynchronous processes in a function. I've discovered that I need to use promises for this, so I spent today learning about them. I've implemented promises in my function and c ...

Capture each touchdown and convert it to currency format

As a novice in the field of JS, I have put in a lot of effort into learning from various sources such as websites, documentation, friends, and other questions on Stack Overflow. However, despite all my efforts, I seem to be stuck at this point. $(docume ...

Front end authentication failed (Angular/Spring stack)

Link to my front end code: http://embed.plnkr.co/toe4XO/. I made adjustments to the authentication/service.js file, see below: 'use strict'; angular.module('Authentication') .factory('AuthenticationService', ['Base ...

Sending the "Enter Key" using JavaScript in Selenium can be achieved by utilizing the "executeScript" function

I'm currently developing an automation flow using IE 11 with Selenium and Java. On a particular web page, I need to input a value in a Text Box and then press Enter. I have successfully managed to input the values using the following code: // The &ap ...

Creating dependent dropdowns using Laravel Inertia Vue: A step-by-step guide

In my AddressController, I have a function called loadCity along with other CRUD functions: public function loadCities(Request $request) { $provinceId = $request->province_id; $cities = Province::where('province_id' ...

Difficulty displaying a progress bar over an overlay

Issue with Progress Bar Visibility in AJAX Call: I have a requirement to display a progress bar in an overlay after the save button is clicked. However, the progress bar is only visible after we receive the response from the AJAX call and display an aler ...

Clicking the React Todo Delete Button instantly clears out all tasks on the list

I am dealing with 2 files: App.js import React, { Component } from 'react'; import './App.css'; import ToDo from './components/ToDo.js'; class App extends Component { constru ...

What is the best way to alternate $httpBackend when[method] declarations in unit tests to handle multiple requests?

When conducting my testing, I set up the model data and mock the response: beforeEach(function(){ var re = new RegExp(/^http\:\/\/.+?\/users-online\/(.+)$/); $httpBackend.whenGET(re).respond({id:12345, usersOnline:5000}); }) ...

Unable to display image in jqGrid binary format

In our system, we use a standard function to retrieve images stored as binaries in the database, and this function works seamlessly throughout the entire system. However, when implementing jqGrid, I encountered difficulties using the existing structure as ...