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.
View Code
/// <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
相关文章推荐
- Part 29 AngularJS intellisense in visual studio
- Part 28 AngularJS default route
- Part 27 Remove # from URL AngularJS
- [AngularJS面面观] 2. scope中的Dirty Checking(脏数据检查) --- Digest Cycle
- AngularJS中,联合使用ng-repeat和ng-if,可以实现对数据删选显示效果,特别适合于用作表单数据的显示
- angularjs-表单验证
- angular中重要指令介绍($eval,$parse和$compile)
- 深究AngularJS——过滤器(filter)
- angularJS指令参数详解
- angularJs中ngModel的坑
- 深究AngularJS——自定义服务详解(factory、service、provider)
- Angularjs中UI Router的使用方法
- AngularJS控制器controller如何通信?
- 深究AngularJS——排序
- Part 23 to 26 Routing in Angular
- AngularJS在IE8的不支持的解决方法
- AngularJS 指令编译原理
- AngularJS与单选框及多选框的双向动态绑定
- 深究AngularJS——$sce的使用
- Yeoman构建AngularJs应用初步