按钮显示ng-hide然后ng-hide

时间:2016-07-13 15:40:58

标签: angularjs

我有单击以显示信息的文本,并且如果再次单击该信息则想隐藏该信息。目前它显示,但不隐藏。

我的代码:

<td ng-click="format(x.Recipient)" ng-show="x.Recipient.Name">
    <a>
         {{x.Recipient.Name}}
    </a>
    </td>
    <td ng-hide="x.Recipient.Name">
         {{x.Recipient}}
    </td>

有什么建议吗?谢谢:))

随访:

被要求张贴我的控制器:

    angular.module('app')
      .controller('QueryCtrl', ['$scope', 'dbCall', 'uuid', '$http', '$cookies',
        function($scope, dbCall, uuid, $http, $cookies) {

          $scope.results = [];
          $scope.error = false;
          $scope.formatted = '';
          $scope.LOCATION = '';
          $scope.processed = false;
          $scope.delivered = false;
          $scope.processedInfo = {};
          $cookies.put("ptLastPage", "/query");
          $scope.successCall = false;

          $scope.format = function(recipient) {
            $scope.formatted = recipient.Name + '\n' + recipient.Email_Address +
              '\n' + recipient.Job_Title +
              '\n' + recipient.Department + '\n' + recipient.Office;
          };

          $scope.toRun = function(err, data) {
            if (err) {
              //console.log(err, err.stack);
              $scope.results = false;
              $scope.error = 'Could not connect to database';
              $scope.$apply();
            } else {
              //console.log(data);
              if (data.Items.length > 0) {
                if (data.Items.length > 1) {
                  data.Items.forEach(function(item) {
                    if (item.Action === 'Processed') {
                      $scope.processed = true;
                    } else if (item.Action === 'Delivered') {
                      $scope.delivered = true;
                    }
                  });
                  data.Items.forEach(function(item) {
                    if ($scope.delivered) {
                      $scope.results.push(item);
                    } else if (item.Action === 'Processed') {
                      $scope.processedInfo = item;
                    } else {
                      $scope.results.push(item);
                    }
                  });
                } else {
                  $scope.results = data.Items[0];
                }
                $scope.error = false;
              } else {
                $scope.results = false;
                $scope.error = 'Tracking Number not found';
              }
              $scope.formatted = '';
              $scope.location = '';
              $scope.$apply();
            }
          };
          $scope.getData = function() {
            $scope.results = [];
            $scope.processed = false;
            $scope.delivered = false;
            //$scope.location = '';
            $scope.processedInfo = {};
            var params = {
              'IndexName': 'TrackingNumber-index',
              'KeyConditionExpression': 'TrackingNumber = :t_num',
              'ExpressionAttributeValues': {
                ':t_num': $scope.trackingNumber
              },
              'ScanIndexForward': false
            };
            return dbCall('query', params, $scope.toRun);
          };

          $scope.postEmail = function(err, data) {
            if (err) {
              //console.log(err, err.stack);
            } else {
              $http.get('file.json').success(function(res) {
                var toSend = {
                  'fromEmail': res.fromEmail,
                  'toAddresses': [$scope.processedInfo.Recipient.Email_Address],
                  'subject': res.subject,
                  'message': 'You have a Package.' +
                    '\n' +
                    '\n' + 'Tracking Number: ' + $scope.processedInfo.TrackingNumber +
                    '\n' + 'Location:' + $scope.LOCATION +
                    '\n' + 'Time: ' + new Date().toLocaleString() +
                    '\n' + 'Delivered by User: ' + $scope.USERNAME
                };
                //console.log(toSend);
                $scope.successCall = true;
                $http.post(
                  'email',
                  toSend);
                $scope.getData();
              });
            }
          };

          $scope.deliver = function() {
            var params = {
              Item: {
                TrackingNumber: $scope.processedInfo.TrackingNumber,
                LoggedByUser: $scope.USERNAME,
                Id: '' + uuid(),
                DateAndTime: new Date().toLocaleString(),
                Action: 'Delivered',
                Location: $scope.LOCATION,
                Recipient: $scope.processedInfo.Recipient,
                Notes: 'none'
              }
            };
            return dbCall('putItem', params, $scope.postEmail);
          };
        }
  ]);

1 个答案:

答案 0 :(得分:0)

您可以在<div id="my-modal" class="modal-content"> 上切换其他媒体资源并将其绑定到// On modal.js $("#my-modal .specific-action").click(...) 。所以你的点击处理程序只需切换新字段。例如:

Recipient

然后,您的点击处理程序只会切换值:

<强> HTML

ng-hide

<强> JS

<td ng-hide="x.Recipient.isVisible">
     {{x.Recipient}}
</td>