Javascript 无法运行AngularJS计时器示例

Javascript 无法运行AngularJS计时器示例,javascript,angularjs,angularjs-scope,angularjs-ng-repeat,Javascript,Angularjs,Angularjs Scope,Angularjs Ng Repeat,当我尝试运行Angular JS timer站点中提到的以下示例时,我发现了一个错误: ng:areq Bad Argument Argument 'MyAppController' is not a function, got undefined http://errors.angularjs.org/1.3.14/ng/areq?p0=MyAppController&p1=not%20a%20function%2C%20got%20undefined at Error (n

当我尝试运行Angular JS timer站点中提到的以下示例时,我发现了一个错误:

ng:areq
Bad Argument
Argument 'MyAppController' is not a function, got undefined

http://errors.angularjs.org/1.3.14/ng/areq?p0=MyAppController&p1=not%20a%20function%2C%20got%20undefined
    at Error (native)
    at file:///C:/ICDP/Angular/angular/angular.min.js:6:417
    at Sb (file:///C:/ICDP/Angular/angular/angular.min.js:19:510)
    at tb (file:///C:/ICDP/Angular/angular/angular.min.js:20:78)
    at file:///C:/ICDP/Angular/angular/angular.min.js:75:331
    at file:///C:/ICDP/Angular/angular/angular.min.js:57:65
<!DOCTYPE html>
<html>
<head>
    <title>AngularJS Example - Multiple Timers 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;
            };
        }
        MyAppController.$inject = ['$scope'];
    </script>
</head>
<body ng-app="MyApp">
    <div ng-controller="MyAppController">
        <h2>AngularJS - Multiple Timers Example</h2>
        <h3>Timer 1: <timer/></h3>
        <h3>Timer 2: <timer interval="2000"/></h3>
        <h3>Timer 3: <timer> minutes,  seconds.</timer></h3>
        <button ng-click="startTimer()" ng-disabled="timerRunning">Start Timers</button>
        <button ng-click="stopTimer()" ng-disabled="!timerRunning">Stop Timers</button>
    </div>
</body>
</html>
ng:areq
错误的论点
参数“MyAppController”不是函数,未定义
http://errors.angularjs.org/1.3.14/ng/areq?p0=MyAppController&p1=not%20a%20function%2C%20got%20undefined
错误(本机)
在file:///C:/ICDP/Angular/angular/angular.min.js:6:417
对某人(file:///C:/ICDP/Angular/angular/angular.min.js:19:510)
结核病(file:///C:/ICDP/Angular/angular/angular.min.js:20:78)
在file:///C:/ICDP/Angular/angular/angular.min.js:75:331
在file:///C:/ICDP/Angular/angular/angular.min.js:57:65
AngularJS示例-多定时器示例
模块('MyApp',['timer']);
函数MyAppController($scope){
$scope.timerRunning=true;
$scope.startTimer=函数(){
$scope.$broadcast('timer-start');
$scope.timerRunning=true;
};
$scope.stopTimer=函数(){
$scope.$broadcast('timer-stop');
$scope.timerRunning=false;
};
}
MyAppController.$inject=['$scope'];
AngularJS-多定时器示例
计时器1:
计时器2:
计时器3:分,秒。
启动计时器
停止计时器
我有以下两个文件包括在内

  <script src="../angular/angular.min.js"></script>
    <script src="../app/js/timer.js"></script>


您没有MyAppController控制器。您必须告诉angular,有一个名为MyAppController的控制器。试试这个来解决你的问题

angular.module('MyApp', ['timer']).controller('MyAppController', MyAppController);

以及可能有用的链接

您没有MyAppController控制器。您必须告诉angular,有一个名为MyAppController的控制器。试试这个来解决你的问题

angular.module('MyApp', ['timer']).controller('MyAppController', MyAppController);

打开Chrome开发者工具(F12),然后打开文件夹:angular timer->examples->angularjs-single-timer.html,你会看到(这只是一个小错误):


AngularJS示例-单计时器示例
角度.module('MyApp',['timer']))
.controller('MyAppController',['$scope',函数($scope){
$scope.timerRunning=true;
$scope.startTimer=函数(){
$scope.$broadcast('timer-start');
$scope.timerRunning=true;
};
$scope.stopTimer=函数(){
$scope.$broadcast('timer-stop');
$scope.timerRunning=false;
};
$scope.$on('timer-stopped',函数(事件、数据){
log('计时器停止-数据=',数据);
});
}]);
AngularJS-单计时器示例
启动计时器
停止定时器


打开Chrome开发者工具(F12),然后打开包含以下文件的文件夹:angular timer->examples->angularjs-single-timer.html,您将看到(这只是一个小错误):


AngularJS示例-单计时器示例
角度.module('MyApp',['timer']))
.controller('MyAppController',['$scope',函数($scope){
$scope.timerRunning=true;
$scope.startTimer=函数(){
$scope.$broadcast('timer-start');
$scope.timerRunning=true;
};
$scope.stopTimer=函数(){
$scope.$broadcast('timer-stop');
$scope.timerRunning=false;
};
$scope.$on('timer-stopped',函数(事件、数据){
log('计时器停止-数据=',数据);
});
}]);
AngularJS-单计时器示例
启动计时器
停止定时器


谢谢。。ICDApp.controller('maintenanceController',['$scope','$filter','$http',function($scope,$filter,$http)…如果我想使用一个现有的控制器,我如何向这个控制器添加[filter]。什么是[filter]?它是您的自定义模块吗?如果是,只需添加这样的行:
var ICDApp=angular.module('ICDApp',['filter'))
然后,例如,您可以在控制器内部使用在“filter”模块中定义的服务,使用方式与“$scope”和“$http”等相同。对不起,我指的是TImer..即使我添加了TImer angular.module('ICDApp',['filter']);时间没有显示..当我单击按钮时,startTimer和stopTimer中的conole.log正在打印,但计时器没有显示。我建议您创建应用程序的plunker或JSFIDLE示例,以便清楚地理解。谢谢..ICDApp.controller('maintenanceController',['$scope','$filter','$http',函数($scope,$filter,$http)…如果我想使用一个现有的控制器,我该如何向其中添加[filter]。什么是[filter]?它是您的自定义模块吗?如果是,只需添加这样的行:
var ICDApp=angular.module('ICDApp',['filter'))
然后,例如,您可以在控制器内部使用在“filter”模块中定义的服务,使用方式与“$scope”和“$http”等相同。对不起,我指的是TImer..即使我添加了TImer angular.module('ICDApp',['filter']);未显示时间..单击按钮时,startTimer和stopTimer中的conole.log将被打印,但计时器未显示。我建议您创建应用程序的plunker或JSFIDLE示例,以便清楚地理解。