您的位置:首页 > Web前端 > AngularJS

Part 30 AngularJS routeparams example

2016-05-15 03:36 633 查看
Here is what we want to do : When we navigate to /students, the list of student names must be displayed as hyperlinks.

/// <reference path="angular.min.js" />
/// <reference path="angular-route.min.js" />

var app = angular
.module("Demo", ["ngRoute"])
.config(function ($routeProvider, $locationProvider) {
$routeProvider
.when("/home", {
templateUrl: "Templates/home.html",
controller: "homeController"
})
.when("/courses", {
templateUrl: "Templates/courses.html",
controller: "coursesController"
})
.when("/students", {
templateUrl: "Templates/students.html",
controller: "studentsController"
})
.when("/students/:id", {
templateUrl: "Templates/studentDetails.html",
controller: "studentDetailsController"
})
.otherwise({
redirectTo: "/home"
})
$locationProvider.html5Mode(true);
})
.controller("homeController", function ($scope) {
$scope.message = "Home Page";
})
.controller("coursesController", function ($scope) {
$scope.courses = ["C#", "VB.NET", "ASP.NET", "SQL Server"];
})
.controller("studentsController", function ($scope, $http) {
$http.get("StudentService.asmx/GetAllStudents")
.then(function (response) {
$scope.students = response.data;
})
})
.controller("studentDetailsController", function ($scope, $http, $routeParams) {
$http({
url: "StudentService.asmx/GetStudent",
method: "get",
params: { id: $routeParams.id }
}).then(function (response) {
$scope.student = response.data;
})
})


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: