0

I have a list of name's and id's. I have displayed it with ng-repeat property. I want to show the corresponding id's along with the name in 1 second on its click.

$scope.showFn = function() {
  $scope.showPopup = true;
  $timeout(function(){
    console.log("timeout");
    $scope.showPopup = false;
  }, 1000);
};

I have created a plunker

https://plnkr.co/edit/kvkgwp60Bxq2MrHrr5Rr?p=preview

Now showing all the id's in a single click. Please help.
Thanks.

1

1 Answer 1

2

Try with below in HTML:

<!DOCTYPE html>
<html ng-app="app">

  <head>
    <script data-require="angular.js@*" data-semver="1.3.0-beta.5" src="https://code.angularjs.org/1.3.0-beta.5/angular.js"></script>
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
  </head>

  <body ng-controller="main">
    <ul>
      <li ng-repeat="item in items">
        <a href="#" ng-click="showFn(item.id)">{{item.name}}</a>
        <span ng-show="showPopup && item.id == shownId">{{item.id}}</span>
      </li>
    </ul>
  </body>

</html>

Controller will be like below:

var app = angular.module('app', [])
  .controller('main', function($scope, $timeout) {
    $scope.items = [{
      "name": "one",
      "id": "1"
    }, {
      "name": "two",
      "id": "2"
    }, {
      "name": "three",
      "id": "3"
    }, {
      "name": "four",
      "id": "4"
    }, {
      "name": "five",
      "id": "5"
    }, {
      "name": "six",
      "id": "6"
    }, {
      "name": "seven",
      "id": "7"
    }]

    $scope.showFn = function(Item) {
      $scope.shownId = Item;
      $scope.showPopup = true;
      $timeout(function() {
        console.log("timeout");
        $scope.showPopup = false;
      }, 1000);
    };

  });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.