简体   繁体   中英

AngularJS : only one line shows up, not the other

AngularJS : only one line shows up, not the other

I have AngularJS code and only one of them shows up in my page

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");
  }());
}

And in the html, I have:

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

And only the first now_time shows up.

How should I set up the variables or anything else to show both?

Put both in the same app:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM