我来找你是因为我想在我的网页中显示来自 Angular 脚本的时间。所以我的 HTML 中有:
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-animate.js"></script>
<p class="alert alert-info">Time is: {{mytime | date:'shortTime'}}</p>
和我的脚本:
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('TimepickerDemoCtrl', function ($scope, $log) {
$scope.mytime = new Date();
$scope.hstep = 1;
$scope.mstep = 15;
$scope.options = {
hstep: [1, 2, 3],
mstep: [1, 5, 10, 15, 25, 30]
};
$scope.ismeridian = true;
$scope.toggleMode = function() {
$scope.ismeridian = ! $scope.ismeridian;
};
$scope.update = function() {
var d = new Date();
d.setHours( 14 );
d.setMinutes( 0 );
$scope.mytime = d;
};
$scope.changed = function () {
$log.log('Time changed to: ' + $scope.mytime);
};
$scope.clear = function() {
$scope.mytime = null;
};
});
但只显示“时间是:”。
有什么想法吗?提前致谢。
最佳答案
我想你错过了 ng-app 和 ng-controller tah
<body ng-app>
<p ng-controller="TimepickerDemoCtrl" class="alert alert-info">Time is: {{myTime | date:'shortTime'}}</p>
</body>
关于javascript - HTML 中 AngularJs 脚本的日期问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38525161/