douyuben9434 2018-10-15 09:16
浏览 91

ng-repeat中的单值

In my main ng-repeat div I have one div which should only contain a single matching value, what I tried now causes the same value to appear in every game because it is in the main ng repeat, what should I do instead of

<div class="row spacing10" ng-controller="latestfeed">
  <div class="col s1 offset-s11 time" ng-repeat="latest in latestfeed">{{ latest.minute }}</div>
</div>

to only get the minute of the event for the matching game?

HTML:

  <div id="live" class="container" ng-controller="games">
    <div ng-repeat="game in games">
      <div class="card-panel">
        <div class="row spacing10">
          <div class="col s11" ng-class="{'bold': game.firstscore > game.secondscore}">{{ game.first}}</div>
          <div class="col s1 customred" ng-class="{'customgreen': game.second > game.second}">{{ game.first|| 0 }}</div>
        </div>
        <div class="row spacing10" ng-controller="latestfeed">
          <div class="col s1 offset-s11 time" ng-repeat="latest in latestfeed">{{ latest.minute }}</div>
        </div>
        <div class="row">
          <div class="col s11" ng-class="{'bold': game.second> game.first }">{{ game.second}}</div>
          <div class="col s1 customred" ng-class="{'customgreen': game.secondscore > game.firstscore }">{{ game.secondscore|| 0 }}</div>
        </div>
      </div>
    </div>
  </div>

app.js

app.controller('games', function ($scope, $http) {
  $http.get('https://www.website.com/app/?data=games').success(function (data) {
    $scope.games= data;
  });
});

app.controller('latestfeed', function ($scope, $http) {
  $http.get('https://www.website.com/app/?data=latestfeed').success(function (data) {
    $scope.latestfeed = data;
  });
});

PHP JSON queries:

games:
$sql->query('SELECT * FROM games WHERE dateofgame = :date');

latestfeed:
        $sql->query('SELECT * FROM event_items, feed, games
                     WHERE event_items.event_id = feed.event_id
                     AND feed.gamenumber = games.gamenumber
                     AND day = :date
                     ORDER BY feed.time DESC LIMIT 1');

games query output in short:

[{"gamenumber":6160,"},{"gamenumber":6161,"}]

latestfeed query output in short:

[{"event_id":4,"gamenumber":6160,"minute":40,"}]

HTML output: One div contains gamenumber 6160 and one div contains gamenumber 6161, the minute 40 should only display in the first div in this case

  • 写回答

1条回答 默认 最新

  • duanning9110 2018-10-15 09:50
    关注

    Fixed it with ng-repeat="latest in latestfeed" ng-if="latest.gamenumber === game.gamenumber", I am new to Angular and did not know that this was possible

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度