4

我想显示一个倒数计时器。我一直在参考以下页面 http://siddii.github.io/angular-timer/

但我收到以下错误。

错误:指令计时器的无效隔离范围定义:@?

谁能告诉我我错过了什么。

索引.html

<!DOCTYPE html>
<html ng-app="app">
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="angular.min.js"></script>
<script type="text/javascript" src="angular-timer.min.js"></script>
<script type="text/javascript" src="app.js"></script>
</head>
<body>
<timer end-time="1451628000000">{{days}} days, {{hours}} hours, {{minutes}} minutes, {{seconds}} seconds.</timer>
</body>
</html>

应用程序.js

var appModule=angular.module('app', ['timer']);
4

2 回答 2

13

尝试这个。它正在工作:

我根据遇到的错误添加了moment.jshumanizeDuration.js库。

希望能帮助到你

<!DOCTYPE html>
<html>

  <head>
   <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.1/angular.min.js"></script>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.js"></script>
   <script src="https://raw.githubusercontent.com/EvanHahn/HumanizeDuration.js/master/humanize-duration.js"></script>
   <script src="https://raw.githubusercontent.com/siddii/angular-timer/master/dist/angular-timer.js"></script>
  </head>

   <body ng-app="app">

    <div ng-controller="ctrl">
      <timer end-time="1451628000000">{{days}} days, {{hours}} hours, {{minutes}} minutes, {{seconds}} seconds.</timer>
	</div>
	
	<script>
	   var app = angular.module('app',['timer']);
			
	   app.controller('ctrl', function($scope){});
	</script>
   </body>
</html>

于 2015-05-20T07:43:08.547 回答
2

您需要引入正确的库才能使计时器工作。

bower install momentjs --save
bower install humanize-duration --save

现在在您的 HTML 中添加依赖项

<script type="text/javascript" src="bower_components/humanize-duration/humanize-duration.js"></script>

<script type="text/javascript" src="bower_components/momentjs/min/moment-with-locales.min.js"></script>
于 2016-02-28T19:58:58.403 回答