我对Angualrjs感到沮丧,因为它一直在抛出错误,或者在我的本地主机上完全无法工作,尽管我完全按照教程。例如,我想测试路由的tutorial。
这就是我得到的,
错误:[$ injector:modulerr] http://errors.angularjs.org/1.2.6/ $注射器/ modulerr P0 =应用&安培; P1 =%5B%24injector%3Aunpr%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.2.6%2F%24injector%2Funpr%3Fp0%3D %2524routeProvider%0As%2F%3C%40http%3A%2F%2Flocalhost%2Ftest%2F2013%2Fjs%2Fangular%2F3%2Fjs%2Fangular.min.js%3A6%0AYb%2FM。%24injector%3C%40http%3A% 2F%2Flocalhost%2Ftest%2F2013%2Fjs%2Fangular%2F3%2Fjs%2Fangular.min.js%3A32%0AC%40http%3A%2F%2Flocalhost%2Ftest%2F2013%2Fjs%2Fangular%2F3%2Fjs%2Fangular.min。 JS%3A30%0AD%40http%3A%2F%2Flocalhost%2Ftest%2F2013%2Fjs%2Fangular%2F3%2Fjs%2Fangular.min.js%3A30%0AE%2F%3C%40http%3A%2F%2Flocalhost%2Ftest% 2F2013%2Fjs%2Fangular%2F3%2Fjs%2Fangular.min.js%3A29%0Aq%40http%3A%2F%2Flocalhost%2Ftest%2F2013%2Fjs%2Fangular%2F3%2Fjs%2Fangular.min.js%3A7%0AE% 40http%3A%2F%2Flocalhost%2Ftest%2F2013%2Fjs%2Fangular%2F3%2Fjs%2Fangular.min.js%3A29%0AYb%40http%3A%2F%2Flocalhost%2Ftest%2F2013%2Fjs%2Fangular%2F3%2Fjs% 2Fangular.min.js%3A32%0AXb%2FC%40http%3A%2F%2Flocalhost%2Ftest%2F2013%2Fjs%2Fangular%2F3%2Fjs%2Fangular.min.js%3A17%0AXb%40HT TP%3A%2F%2Flocalhost%2Ftest%2F2013%2Fjs%2Fangular%2F3%2Fjs%2Fangular.min.js%3A18%0ARc%40http%3A%2F%2Flocalhost%2Ftest%2F2013%2Fjs%2Fangular%2F3%2Fjs% 2Fangular.min.js%3A17%0A%40http%3A%2F%2Flocalhost%2Ftest%2F2013%2Fjs%2Fangular%2F3%2Fjs%2Fangular.min.js%3A200%0Ax.Callbacks%2FC%40http%3A%2F% 2Flocalhost%2Ftest%2F2013%2Fjs%2Fangular%2F3%2Fjs%2Fjquery-1.10.1.min.js%3A4%0Ax.Callbacks%2Fp.fireWith%40http%3A%2F%2Flocalhost%2Ftest%2F2013%2Fjs%2Fangular% 2F3%2Fjs%2Fjquery-1.10.1.min.js%3A4%0A.ready%40http%3A%2F%2Flocalhost%2Ftest%2F2013%2Fjs%2Fangular%2F3%2Fjs%2Fjquery-1.10.1.min.js% 3A4%0Aq%40http%3A%2F%2Flocalhost%2Ftest%2F2013%2Fjs%2Fangular%2F3%2Fjs%2Fjquery-1.10.1.min.js%3A4%0A
... C-1)+ “=” + encodeURIComponent方法( “功能” == typeof运算 参数[C]?参数并[c] .toStrin ...
这就是我在Backbonejs中轻松实现的方法!
var AppRouter = Backbone.Router.extend({
routes: {
'': 'renderListContactsPage',
'list_contacts': 'renderListContactsPage',
'add_new_contact': 'renderAddNewContactPage',
'search_contacts': 'renderSearchContactsPage',
'edit_contact/:id': 'renderEditContactPage',
'!article/edit/:url/': 'renderDynamicPage',
':parent/:url/': 'renderDynamicPage2',
'!:module/:branch/:method/set:setnumber/page:pagenumber/': 'renderDynamicPage3',
'!:module/:branch/:method?set=:setnumber&page=:pagenumber': 'renderDynamicPage3'
},
renderAddNewContactPage: function () {
var projectAddView = new ProjectAddView();
projectAddView.addContactPage();
},
renderListContactsPage: function () {
var projectListView = new ProjectListView();
projectListView.listContactsPage();
},
renderSearchContactsPage: function () {
var projectSearchView = new ProjectSearchView();
projectSearchView.searchContactPage();
}
...
我在Angular中错过了什么?我使用的是最新版本 - v1.2.6 ,他们的文档很差!
修改
HTML,
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>AngularJS</title>
<meta charset="utf-8">
<script src="js/jquery-1.10.1.min.js"></script>
<script src="js/angular.min.js"></script>
<script src="js/angular-route.js"></script>
<script src="js/app.js" type="text/javascript"></script>
</head>
<body>
<div ng-app="app">
<ng-view></ng-view>
</div>
</body>
</html>
角,
var app = angular.module("app", []);
app.config(function($routeProvider){
$routeProvider.when("/",
{
templateUrl: "app.html",
controller: "AppCtrl"
}
);
});
app.controller("AppCtrl", function($scope){
$scope.model = {
message: "This is my app!!!"
}
});
答案 0 :(得分:5)
您需要在模块声明中将ngRoute
作为依赖项注入。
var app = angular.module("app", []);
应该是
var app = angular.module("app", ['ngRoute']);
答案 1 :(得分:4)
var app = angular.module("app", ['ngRoute']);
app.config(['$routeProvider', function($routeProvider){
$routeProvider.when("/",
{
templateUrl: "app.html",
controller: "AppCtrl"
}
);
}]);