角度计时器不工作

时间:2015-05-20 06:39:53

标签: angularjs angular-timer

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

但我收到以下错误。

  

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

有人可以告诉我,我错过了什么。

的index.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>

app.js

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

2 个答案:

答案 0 :(得分:13)

试试这个。它在工作:

我根据错误添加了moment.jshumanizeDuration.js个库。

希望有所帮助

&#13;
&#13;
<!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>
&#13;
&#13;
&#13;

答案 1 :(得分: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>