1

在我的网络应用程序中(前面有 angularJs,后面有 Symfony2)我需要集成一个计时器(测验者的倒计时)我找到了这个计时器https://github.com/siddii/angular- github上的计时器,它似乎很酷,但我的webapp中的集成不起作用但是当我尝试在事件(按钮单击)上启动计数器时它不起作用,事实上我尝试了这个脚本:

<!DOCTYPE html>
<html>
<head>
<title>AngularJS Example - Single Timer Example</title>
<script src="../angular/angular.min.js"></script>
<script src="../app/js/timer.js"></script>
<script>
    angular.module('MyApp', ['timer']);
    function MyAppController($scope) {
        $scope.timerRunning = true;

        $scope.startTimer = function (){
            $scope.$broadcast('timer-start');
            $scope.timerRunning = true;
        };

        $scope.stopTimer = function (){
            $scope.$broadcast('timer-stop');
            $scope.timerRunning = false;
        };

        $scope.$on('timer-stopped', function (event, data){
            console.log('Timer Stopped - data = ', data);
        });
    }
    MyAppController.$inject = ['$scope'];
</script>
</head>
<body ng-app="MyApp">
    <div ng-controller="MyAppController">
    <h1>AngularJS - Single Timer Example</h1>
    <h3><timer/></h3>
    <button ng-click="startTimer()" ng-disabled="timerRunning">Start   Timer</button>
    <button ng-click="stopTimer()" ng-disabled="!timerRunning">Stop Timer</button>
    </div>
    <br/>
</body>
</html>

我得到了这个错误:

Argument 'MyAppController' is not a function, got undefined

任何人都可以帮助我吗?

经过一些更改后,我的代码变为:

   <!DOCTYPE html>
<html>
 <head>
   <title>AngularJS Example - Single Timer Example</title>
    <script src="../angular/angular.min.js"></script>
    <script src="../app/js/timer.js"></script>
    <script>
      var myApp =  angular.module('myApp', ['timer']);
        myApp.controller('MyAppController', ['$scope', function ($scope) 

    {
        $scope.timerRunning = true;

        $scope.startTimer = function (){
            $scope.$broadcast('timer-start');
            $scope.timerRunning = true;
    };

    $scope.stopTimer = function (){
        $scope.$broadcast('timer-stop');
        $scope.timerRunning = false;
    };

    $scope.$on('timer-stopped', function (event, data){
        console.log('Timer Stopped - data = ', data);
    });
}]).$inject = ['$scope'];

 </script>
 </head>
 <body ng-app="myApp">
<div ng-controller="MyAppController">
<h1>AngularJS - Single Timer Example</h1>
<h3><timer/></h3>
<button ng-click="startTimer()" ng-disabled="timerRunning">Start   Timer</button>
<button ng-click="stopTimer()" ng-disabled="!timerRunning">Stop Timer</button>
</div>
  <br/>
</body>
</html>

我得到了这个美丽:/

Unknown provider: I18nServiceProvider <- I18nService
4

0 回答 0