本文介绍了Angularjs路由VS Backbonejs路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到与Angualrjs沮丧,因为它不断抛出错误或失败,只是我虽然也跟着教程确切地在我的本地在所有工作。例如,这我想测试出来的路由。
这是我所得到的,
This is how I could do it in Backbonejs easily!
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();
}
...
What have I missed in Angular? I am using the latest version of it - v1.2.6 and they have such a poor documentation!
EDIT:
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>
angular,
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!!!"
}
});
解决方案
You need ngRoute
to be injected as a dependency in your module declaration.
var app = angular.module("app", []);
should be
var app = angular.module("app", ['ngRoute']);
这篇关于Angularjs路由VS Backbonejs路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!