Javascript AngularJS-从1.2.9迁移到1.4.9时出错

Javascript AngularJS-从1.2.9迁移到1.4.9时出错,javascript,html,angularjs,Javascript,Html,Angularjs,我是AngularJs的新手,当我尝试使用AngularJs的1.4.9版而不是1.2.9版(我使用时没有问题)时,我会出错。我通过以下方式了解到需要声明新函数: angular.module('scotchApp', []).controller('prenotazioneController', [function ($scope) { //$scope.message = 'Pagina Delle info!!!';// }]); 而不是: function getTa

我是AngularJs的新手,当我尝试使用AngularJs的1.4.9版而不是1.2.9版(我使用时没有问题)时,我会出错。我通过以下方式了解到需要声明新函数:

    angular.module('scotchApp', []).controller('prenotazioneController', [function ($scope) {
    //$scope.message = 'Pagina Delle info!!!';//
}]);
而不是:

function getTask($scope, $http, Base64) {
//do something
};
但我总是遇到这样的错误:

    // create the module and name it scotchApp
var scotchApp = angular.module('scotchApp', ['ngRoute']);

// configure our routes
scotchApp.config(function ($routeProvider) {
    $routeProvider

    // route for the home page
        .when('/', {
        templateUrl: 'view/home.html',
        controller: 'mainController'
    })

    // route for the about page
    .when('/prenotazione', {
        templateUrl: 'view/prenotazione.html',
        controller: 'prenotazioneController'
    })

    .when('/login', {
        templateUrl: 'view/login.html',
        controller: 'loginController'
    });
});

// create the controller and inject Angular's $scope
angular
    .module('scotchApp', [])
    .controller('mainController', [function ($scope) {
        // create a message to display in our view
         $scope.message = 'Vai alla Prenotazione';
    }]);

angular.module('scotchApp', []).controller('prenotazioneController', [function ($scope) {
    /*   $scope.message = 'Pagina Delle info!!!';*/
}]);

angular.module('scotchApp', []).controller('loginController', [function ($scope) {
    $scope.message = '*Necessario per eseguire una prenotazione';
}]);
<html ng-app="scotchApp">

<head>
    <!-- SCROLLS -->
    <link href='https://fonts.googleapis.com/css?family=PT+Sans:400italic,400,700,700italic' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" />
    <link href="style.css" rel="stylesheet" type="text/css">
<!-- SPELLS -->

<script src="//code.angularjs.org/1.4.9/angular.min.js"></script>
<script src="//code.angularjs.org/1.4.9/angular-route.min.js"></script>
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript" src="test.js"></script></head>
angular.module('scotchApp', [])
    .controller(...)
angular
   .module('scotchApp')
   .controller(...)
angular.module("app", []); // creates a module.
angular.module("app");    // reference a module.
错误:ng:areq 错误的论点-- 参数“mainController”不是函数,未定义

我想错误是指这段代码,但我已经改变了声明函数的方式

在JS中:

    // create the module and name it scotchApp
var scotchApp = angular.module('scotchApp', ['ngRoute']);

// configure our routes
scotchApp.config(function ($routeProvider) {
    $routeProvider

    // route for the home page
        .when('/', {
        templateUrl: 'view/home.html',
        controller: 'mainController'
    })

    // route for the about page
    .when('/prenotazione', {
        templateUrl: 'view/prenotazione.html',
        controller: 'prenotazioneController'
    })

    .when('/login', {
        templateUrl: 'view/login.html',
        controller: 'loginController'
    });
});

// create the controller and inject Angular's $scope
angular
    .module('scotchApp', [])
    .controller('mainController', [function ($scope) {
        // create a message to display in our view
         $scope.message = 'Vai alla Prenotazione';
    }]);

angular.module('scotchApp', []).controller('prenotazioneController', [function ($scope) {
    /*   $scope.message = 'Pagina Delle info!!!';*/
}]);

angular.module('scotchApp', []).controller('loginController', [function ($scope) {
    $scope.message = '*Necessario per eseguire una prenotazione';
}]);
<html ng-app="scotchApp">

<head>
    <!-- SCROLLS -->
    <link href='https://fonts.googleapis.com/css?family=PT+Sans:400italic,400,700,700italic' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" />
    <link href="style.css" rel="stylesheet" type="text/css">
<!-- SPELLS -->

<script src="//code.angularjs.org/1.4.9/angular.min.js"></script>
<script src="//code.angularjs.org/1.4.9/angular-route.min.js"></script>
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript" src="test.js"></script></head>
angular.module('scotchApp', [])
    .controller(...)
angular
   .module('scotchApp')
   .controller(...)
angular.module("app", []); // creates a module.
angular.module("app");    // reference a module.
在HTML中:

    // create the module and name it scotchApp
var scotchApp = angular.module('scotchApp', ['ngRoute']);

// configure our routes
scotchApp.config(function ($routeProvider) {
    $routeProvider

    // route for the home page
        .when('/', {
        templateUrl: 'view/home.html',
        controller: 'mainController'
    })

    // route for the about page
    .when('/prenotazione', {
        templateUrl: 'view/prenotazione.html',
        controller: 'prenotazioneController'
    })

    .when('/login', {
        templateUrl: 'view/login.html',
        controller: 'loginController'
    });
});

// create the controller and inject Angular's $scope
angular
    .module('scotchApp', [])
    .controller('mainController', [function ($scope) {
        // create a message to display in our view
         $scope.message = 'Vai alla Prenotazione';
    }]);

angular.module('scotchApp', []).controller('prenotazioneController', [function ($scope) {
    /*   $scope.message = 'Pagina Delle info!!!';*/
}]);

angular.module('scotchApp', []).controller('loginController', [function ($scope) {
    $scope.message = '*Necessario per eseguire una prenotazione';
}]);
<html ng-app="scotchApp">

<head>
    <!-- SCROLLS -->
    <link href='https://fonts.googleapis.com/css?family=PT+Sans:400italic,400,700,700italic' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" />
    <link href="style.css" rel="stylesheet" type="text/css">
<!-- SPELLS -->

<script src="//code.angularjs.org/1.4.9/angular.min.js"></script>
<script src="//code.angularjs.org/1.4.9/angular-route.min.js"></script>
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript" src="test.js"></script></head>
angular.module('scotchApp', [])
    .controller(...)
angular
   .module('scotchApp')
   .controller(...)
angular.module("app", []); // creates a module.
angular.module("app");    // reference a module.


切换导航



您错误地引用了
应用程序
模块:

您的代码:

    // create the module and name it scotchApp
var scotchApp = angular.module('scotchApp', ['ngRoute']);

// configure our routes
scotchApp.config(function ($routeProvider) {
    $routeProvider

    // route for the home page
        .when('/', {
        templateUrl: 'view/home.html',
        controller: 'mainController'
    })

    // route for the about page
    .when('/prenotazione', {
        templateUrl: 'view/prenotazione.html',
        controller: 'prenotazioneController'
    })

    .when('/login', {
        templateUrl: 'view/login.html',
        controller: 'loginController'
    });
});

// create the controller and inject Angular's $scope
angular
    .module('scotchApp', [])
    .controller('mainController', [function ($scope) {
        // create a message to display in our view
         $scope.message = 'Vai alla Prenotazione';
    }]);

angular.module('scotchApp', []).controller('prenotazioneController', [function ($scope) {
    /*   $scope.message = 'Pagina Delle info!!!';*/
}]);

angular.module('scotchApp', []).controller('loginController', [function ($scope) {
    $scope.message = '*Necessario per eseguire una prenotazione';
}]);
<html ng-app="scotchApp">

<head>
    <!-- SCROLLS -->
    <link href='https://fonts.googleapis.com/css?family=PT+Sans:400italic,400,700,700italic' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" />
    <link href="style.css" rel="stylesheet" type="text/css">
<!-- SPELLS -->

<script src="//code.angularjs.org/1.4.9/angular.min.js"></script>
<script src="//code.angularjs.org/1.4.9/angular-route.min.js"></script>
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript" src="test.js"></script></head>
angular.module('scotchApp', [])
    .controller(...)
angular
   .module('scotchApp')
   .controller(...)
angular.module("app", []); // creates a module.
angular.module("app");    // reference a module.
通过使用带有括号的
angular.module('scotchApp',[])
[]实际上每次都会覆盖应用程序模块

将其更改为:

    // create the module and name it scotchApp
var scotchApp = angular.module('scotchApp', ['ngRoute']);

// configure our routes
scotchApp.config(function ($routeProvider) {
    $routeProvider

    // route for the home page
        .when('/', {
        templateUrl: 'view/home.html',
        controller: 'mainController'
    })

    // route for the about page
    .when('/prenotazione', {
        templateUrl: 'view/prenotazione.html',
        controller: 'prenotazioneController'
    })

    .when('/login', {
        templateUrl: 'view/login.html',
        controller: 'loginController'
    });
});

// create the controller and inject Angular's $scope
angular
    .module('scotchApp', [])
    .controller('mainController', [function ($scope) {
        // create a message to display in our view
         $scope.message = 'Vai alla Prenotazione';
    }]);

angular.module('scotchApp', []).controller('prenotazioneController', [function ($scope) {
    /*   $scope.message = 'Pagina Delle info!!!';*/
}]);

angular.module('scotchApp', []).controller('loginController', [function ($scope) {
    $scope.message = '*Necessario per eseguire una prenotazione';
}]);
<html ng-app="scotchApp">

<head>
    <!-- SCROLLS -->
    <link href='https://fonts.googleapis.com/css?family=PT+Sans:400italic,400,700,700italic' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" />
    <link href="style.css" rel="stylesheet" type="text/css">
<!-- SPELLS -->

<script src="//code.angularjs.org/1.4.9/angular.min.js"></script>
<script src="//code.angularjs.org/1.4.9/angular-route.min.js"></script>
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript" src="test.js"></script></head>
angular.module('scotchApp', [])
    .controller(...)
angular
   .module('scotchApp')
   .controller(...)
angular.module("app", []); // creates a module.
angular.module("app");    // reference a module.
您只需创建一次应用程序模块,然后引用它

创建模块:

    // create the module and name it scotchApp
var scotchApp = angular.module('scotchApp', ['ngRoute']);

// configure our routes
scotchApp.config(function ($routeProvider) {
    $routeProvider

    // route for the home page
        .when('/', {
        templateUrl: 'view/home.html',
        controller: 'mainController'
    })

    // route for the about page
    .when('/prenotazione', {
        templateUrl: 'view/prenotazione.html',
        controller: 'prenotazioneController'
    })

    .when('/login', {
        templateUrl: 'view/login.html',
        controller: 'loginController'
    });
});

// create the controller and inject Angular's $scope
angular
    .module('scotchApp', [])
    .controller('mainController', [function ($scope) {
        // create a message to display in our view
         $scope.message = 'Vai alla Prenotazione';
    }]);

angular.module('scotchApp', []).controller('prenotazioneController', [function ($scope) {
    /*   $scope.message = 'Pagina Delle info!!!';*/
}]);

angular.module('scotchApp', []).controller('loginController', [function ($scope) {
    $scope.message = '*Necessario per eseguire una prenotazione';
}]);
<html ng-app="scotchApp">

<head>
    <!-- SCROLLS -->
    <link href='https://fonts.googleapis.com/css?family=PT+Sans:400italic,400,700,700italic' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" />
    <link href="style.css" rel="stylesheet" type="text/css">
<!-- SPELLS -->

<script src="//code.angularjs.org/1.4.9/angular.min.js"></script>
<script src="//code.angularjs.org/1.4.9/angular-route.min.js"></script>
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript" src="test.js"></script></head>
angular.module('scotchApp', [])
    .controller(...)
angular
   .module('scotchApp')
   .controller(...)
angular.module("app", []); // creates a module.
angular.module("app");    // reference a module.
引用模块:

    // create the module and name it scotchApp
var scotchApp = angular.module('scotchApp', ['ngRoute']);

// configure our routes
scotchApp.config(function ($routeProvider) {
    $routeProvider

    // route for the home page
        .when('/', {
        templateUrl: 'view/home.html',
        controller: 'mainController'
    })

    // route for the about page
    .when('/prenotazione', {
        templateUrl: 'view/prenotazione.html',
        controller: 'prenotazioneController'
    })

    .when('/login', {
        templateUrl: 'view/login.html',
        controller: 'loginController'
    });
});

// create the controller and inject Angular's $scope
angular
    .module('scotchApp', [])
    .controller('mainController', [function ($scope) {
        // create a message to display in our view
         $scope.message = 'Vai alla Prenotazione';
    }]);

angular.module('scotchApp', []).controller('prenotazioneController', [function ($scope) {
    /*   $scope.message = 'Pagina Delle info!!!';*/
}]);

angular.module('scotchApp', []).controller('loginController', [function ($scope) {
    $scope.message = '*Necessario per eseguire una prenotazione';
}]);
<html ng-app="scotchApp">

<head>
    <!-- SCROLLS -->
    <link href='https://fonts.googleapis.com/css?family=PT+Sans:400italic,400,700,700italic' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" />
    <link href="style.css" rel="stylesheet" type="text/css">
<!-- SPELLS -->

<script src="//code.angularjs.org/1.4.9/angular.min.js"></script>
<script src="//code.angularjs.org/1.4.9/angular-route.min.js"></script>
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript" src="test.js"></script></head>
angular.module('scotchApp', [])
    .controller(...)
angular
   .module('scotchApp')
   .controller(...)
angular.module("app", []); // creates a module.
angular.module("app");    // reference a module.
下面是一个简单的例子:

(function () {

    var app = angular.module("app", []);

    app.controller("MainController", MainController);

    MainController.$inject = ["$http"];

    function MainController($http) {

    }

})();

下面是一个使用您的代码风格的示例。希望这有助于澄清一些问题。

您错误地引用了
应用程序
模块:

您的代码:

    // create the module and name it scotchApp
var scotchApp = angular.module('scotchApp', ['ngRoute']);

// configure our routes
scotchApp.config(function ($routeProvider) {
    $routeProvider

    // route for the home page
        .when('/', {
        templateUrl: 'view/home.html',
        controller: 'mainController'
    })

    // route for the about page
    .when('/prenotazione', {
        templateUrl: 'view/prenotazione.html',
        controller: 'prenotazioneController'
    })

    .when('/login', {
        templateUrl: 'view/login.html',
        controller: 'loginController'
    });
});

// create the controller and inject Angular's $scope
angular
    .module('scotchApp', [])
    .controller('mainController', [function ($scope) {
        // create a message to display in our view
         $scope.message = 'Vai alla Prenotazione';
    }]);

angular.module('scotchApp', []).controller('prenotazioneController', [function ($scope) {
    /*   $scope.message = 'Pagina Delle info!!!';*/
}]);

angular.module('scotchApp', []).controller('loginController', [function ($scope) {
    $scope.message = '*Necessario per eseguire una prenotazione';
}]);
<html ng-app="scotchApp">

<head>
    <!-- SCROLLS -->
    <link href='https://fonts.googleapis.com/css?family=PT+Sans:400italic,400,700,700italic' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" />
    <link href="style.css" rel="stylesheet" type="text/css">
<!-- SPELLS -->

<script src="//code.angularjs.org/1.4.9/angular.min.js"></script>
<script src="//code.angularjs.org/1.4.9/angular-route.min.js"></script>
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript" src="test.js"></script></head>
angular.module('scotchApp', [])
    .controller(...)
angular
   .module('scotchApp')
   .controller(...)
angular.module("app", []); // creates a module.
angular.module("app");    // reference a module.
通过使用带有括号的
angular.module('scotchApp',[])
[]实际上每次都会覆盖应用程序模块

将其更改为:

    // create the module and name it scotchApp
var scotchApp = angular.module('scotchApp', ['ngRoute']);

// configure our routes
scotchApp.config(function ($routeProvider) {
    $routeProvider

    // route for the home page
        .when('/', {
        templateUrl: 'view/home.html',
        controller: 'mainController'
    })

    // route for the about page
    .when('/prenotazione', {
        templateUrl: 'view/prenotazione.html',
        controller: 'prenotazioneController'
    })

    .when('/login', {
        templateUrl: 'view/login.html',
        controller: 'loginController'
    });
});

// create the controller and inject Angular's $scope
angular
    .module('scotchApp', [])
    .controller('mainController', [function ($scope) {
        // create a message to display in our view
         $scope.message = 'Vai alla Prenotazione';
    }]);

angular.module('scotchApp', []).controller('prenotazioneController', [function ($scope) {
    /*   $scope.message = 'Pagina Delle info!!!';*/
}]);

angular.module('scotchApp', []).controller('loginController', [function ($scope) {
    $scope.message = '*Necessario per eseguire una prenotazione';
}]);
<html ng-app="scotchApp">

<head>
    <!-- SCROLLS -->
    <link href='https://fonts.googleapis.com/css?family=PT+Sans:400italic,400,700,700italic' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" />
    <link href="style.css" rel="stylesheet" type="text/css">
<!-- SPELLS -->

<script src="//code.angularjs.org/1.4.9/angular.min.js"></script>
<script src="//code.angularjs.org/1.4.9/angular-route.min.js"></script>
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript" src="test.js"></script></head>
angular.module('scotchApp', [])
    .controller(...)
angular
   .module('scotchApp')
   .controller(...)
angular.module("app", []); // creates a module.
angular.module("app");    // reference a module.
您只需创建一次应用程序模块,然后引用它

创建模块:

    // create the module and name it scotchApp
var scotchApp = angular.module('scotchApp', ['ngRoute']);

// configure our routes
scotchApp.config(function ($routeProvider) {
    $routeProvider

    // route for the home page
        .when('/', {
        templateUrl: 'view/home.html',
        controller: 'mainController'
    })

    // route for the about page
    .when('/prenotazione', {
        templateUrl: 'view/prenotazione.html',
        controller: 'prenotazioneController'
    })

    .when('/login', {
        templateUrl: 'view/login.html',
        controller: 'loginController'
    });
});

// create the controller and inject Angular's $scope
angular
    .module('scotchApp', [])
    .controller('mainController', [function ($scope) {
        // create a message to display in our view
         $scope.message = 'Vai alla Prenotazione';
    }]);

angular.module('scotchApp', []).controller('prenotazioneController', [function ($scope) {
    /*   $scope.message = 'Pagina Delle info!!!';*/
}]);

angular.module('scotchApp', []).controller('loginController', [function ($scope) {
    $scope.message = '*Necessario per eseguire una prenotazione';
}]);
<html ng-app="scotchApp">

<head>
    <!-- SCROLLS -->
    <link href='https://fonts.googleapis.com/css?family=PT+Sans:400italic,400,700,700italic' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" />
    <link href="style.css" rel="stylesheet" type="text/css">
<!-- SPELLS -->

<script src="//code.angularjs.org/1.4.9/angular.min.js"></script>
<script src="//code.angularjs.org/1.4.9/angular-route.min.js"></script>
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript" src="test.js"></script></head>
angular.module('scotchApp', [])
    .controller(...)
angular
   .module('scotchApp')
   .controller(...)
angular.module("app", []); // creates a module.
angular.module("app");    // reference a module.
引用模块:

    // create the module and name it scotchApp
var scotchApp = angular.module('scotchApp', ['ngRoute']);

// configure our routes
scotchApp.config(function ($routeProvider) {
    $routeProvider

    // route for the home page
        .when('/', {
        templateUrl: 'view/home.html',
        controller: 'mainController'
    })

    // route for the about page
    .when('/prenotazione', {
        templateUrl: 'view/prenotazione.html',
        controller: 'prenotazioneController'
    })

    .when('/login', {
        templateUrl: 'view/login.html',
        controller: 'loginController'
    });
});

// create the controller and inject Angular's $scope
angular
    .module('scotchApp', [])
    .controller('mainController', [function ($scope) {
        // create a message to display in our view
         $scope.message = 'Vai alla Prenotazione';
    }]);

angular.module('scotchApp', []).controller('prenotazioneController', [function ($scope) {
    /*   $scope.message = 'Pagina Delle info!!!';*/
}]);

angular.module('scotchApp', []).controller('loginController', [function ($scope) {
    $scope.message = '*Necessario per eseguire una prenotazione';
}]);
<html ng-app="scotchApp">

<head>
    <!-- SCROLLS -->
    <link href='https://fonts.googleapis.com/css?family=PT+Sans:400italic,400,700,700italic' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" />
    <link href="style.css" rel="stylesheet" type="text/css">
<!-- SPELLS -->

<script src="//code.angularjs.org/1.4.9/angular.min.js"></script>
<script src="//code.angularjs.org/1.4.9/angular-route.min.js"></script>
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript" src="test.js"></script></head>
angular.module('scotchApp', [])
    .controller(...)
angular
   .module('scotchApp')
   .controller(...)
angular.module("app", []); // creates a module.
angular.module("app");    // reference a module.
下面是一个简单的例子:

(function () {

    var app = angular.module("app", []);

    app.controller("MainController", MainController);

    MainController.$inject = ["$http"];

    function MainController($http) {

    }

})();

下面是一个使用您的代码风格的示例。希望这有助于澄清一些问题。

谢谢您的回答。我试图从
angular.module('scotchApp',[])
中删除[],但出现了相同的错误。。。我还尝试使用这个:
(函数(){angular.module(“scotchApp”).controller(“mainController”,mainController);mainController.$inject=[“$scope”];函数mainController($scope){$scope.message='Vai alla Prenotazione';};})但不走运。@Luke你有我们可以查看的代码吗?或者这是专有代码吗?@Luke我继续为你做了一个plunkr示例。希望有帮助。谢谢你的帮助!是的,这有助于更好地理解!他们改变了很多事情!但是如果我,而不是这个(例如):
scotchApp.controller(“MainController”,[“$scope”,function($scope){$scope.message=“Vai alla Prenotazione”;}])有以下内容:
.controller('instanceziateprocess',[function($scope,$http,$window,Base64){…}
它将是:
scotchApp.controller('instanceziateprocess',[“$scope”,“$http”,“$window”,“Base64”,function($scope,$http,$window,Base64){…});
?谢谢again@Luke是的,您是正确的,您需要告诉Angular您想要注入的
服务依赖项
,因此需要包括
$scope
$http
等。答案中显示的示例是使用John Papa的样式指南,因为它是相当知名和公认的。这里是指向它的链接,Angular tea我支持他。谢谢你的回答。我试图从
angular.module('scotchApp',[])
中删除[],但出现了相同的错误…我也尝试使用这个:
(function(){angular.module(“scotchApp”).controller(“mainController”,mainController);mainController.$inject=[“$scope”];函数mainController($scope){$scope.message='Vai alla Prenotazione';};})
但不走运。@Luke你有我们可以查看的代码吗?或者这是专有代码吗?@Luke我继续为你做了一个plunkr示例。希望有帮助。感谢你的plunkr!是的,这有助于更好地理解!他们改变了很多事情!但是如果我,而不是这个(例如):
scotchApp.controller(“MainController“,[“$scope”,function($scope){$scope.message=“Vai alla Prenotazione”;}]);
有以下内容:
.controller('InstanziateProcess',[function($scope,$http,$window,Base64){……}
它将是:
scotchap.controller(“InstanziateProcess”,[“$scope”,“$http”,“$window”,“Base64”,函数($scope,$http,$window,Base64){…}]);
?谢谢again@Luke是的,您是正确的,您需要告诉Angular您想要注入的
服务依赖项
,因此需要包括
$scope
$http
等。答案中显示的示例是使用John Papa的样式指南,因为它是相当知名和公认的。这里是指向它的链接,Angular tea我支持他。