我来找你,因为在我的网页中我想显示来自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;
};
});
但只显示“时间是:”。
有什么想法吗?提前谢谢。
答案 0 :(得分:2)
我认为你错过了ng-app和ng-controller tah
<body ng-app>
<p ng-controller="TimepickerDemoCtrl" class="alert alert-info">Time is: {{myTime | date:'shortTime'}}</p>
</body>
答案 1 :(得分:1)
检查完你提供的代码后,我去了Plunker进行测试。我注意到的第一件事是你没有引用ng-app中的模块。
ng-app="ui.bootstrap.demo"
第二件事是控制台显示了与ui.bootstrap相关的模块依赖错误。我只是添加了依赖,一切都很好。
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/2.0.0/ui-bootstrap.js"></script>
请检查the完整的工作示例。
答案 2 :(得分:0)
您在html中提供了错误的名称,将myTime更改为mytime
时间是:{{mytime |日期: '短时'}}
答案 3 :(得分:0)
您在HTML文件中写错了。 即&#34; myTime&#34;。将其更改为&#34; mytime&#34;
时间是:{{mytime |日期:&#39;短时&#39;}}