您應該使用ngRoute。通過「ngRoute」的禮貌,您可以通過特定的URL將用戶重定向到特定的視圖。請對此進行一些研究。假設你解決了你的觀點和重定向問題。你將如何從服務器端獲取數據?這時我建議你看看服務和工廠對象。 希望它有幫助。
示例代碼:
// create the module and name it exApp
// also include ngRoute for all our routing needs
var exApp= angular.module('exApp', ['ngRoute']);
// configure our routes
exApp.config(function($routeProvider) {
$routeProvider
// route for the home page
.when('/', {
templateUrl : 'pages/home.html',
controller : 'mainController'
})
// route for the about page
.when('/about', {
templateUrl : 'pages/about.html',
controller : 'aboutController'
})
// route for the contact page
.when('/contact', {
templateUrl : 'pages/contact.html',
controller : 'contactController'
});
});
// create the controller and inject Angular's $scope
exApp.controller('mainController', function($scope) {
// create a message to display in our view
$scope.message = 'Everyone come and see how good I look!';
});
exApp.controller('aboutController', function($scope) {
$scope.message = 'Look! I am an about page.';
});
exApp.controller('contactController', function($scope) {
$scope.message = 'Contact us! JK. This is just a demo.';
});
https://github.com/angular-ui/ui-router – pegla