簡體   English   中英

AngularJS:僅顯示一行,另一行不顯示

[英]AngularJS : only one line shows up, not the other

AngularJS:僅顯示一行,另一行不顯示

我有AngularJS代碼,只有一個顯示在我的頁面中

function Today($scope, $timeout) {
  $scope.now_time = 0;

  (function update() {
    $timeout(update, 1000);
    var now = moment();
    $scope.now_time = now.format("ddd, MMM Do, h:mm:ss a");
  }());
}


function Yesterday($scope, $timeout) {
  $scope.yst_date = 0;

  (function update() {
    $timeout(update, 1000);
    var yst = moment().subtract('days', 1);
    $scope.yst_date = yst.format("ddd, MMM Do");
  }());
}

在html中,我有:

<div ng-app ng-controller="Today">{{now_time}}</div>
<div ng-app ng-controller="Yesterday">{{yst_date}}</div>

而且只有第一個now_time出現。

我應該如何設置變量或其他任何東西來顯示兩者?

將它們放在同一個應用中:

<div ng-app>
  <div ng-controller="Today">{{now_time}}</div>
  <div ng-controller="Yesterday">{{yst_date}}</div>
</div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM