700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > angular跳转指定页面_AngularJS之页面跳转Route

angular跳转指定页面_AngularJS之页面跳转Route

时间:2023-10-10 15:22:10

相关推荐

angular跳转指定页面_AngularJS之页面跳转Route

AngulagJs的页面使用Route跳转

1.除了引用AngularJs.js外,还要引用路由JS,"~/Scripts/angularjs/angular-route.js"

2.通过$routeProvider定义路由,示例

var testModule = angular.module('testModule', ['ngRoute']);

testModule.config(['$routeProvider', function($routeProvider) {

$routeProvider.when('/2', {//'/2'定义的路由路径,以后通过此路径访问,通常定义为短路径

templateUrl: "/home/index2",//"/home/index2"是路由实际访问的路径,可以是 mvc的访问路径(如此例),也可是具体的页面路径,如“test/test.html"

controller:'testController'//路由跳转的controller,后面必须定义此控制器

});

$routeProvider.when('/3', {

templateUrl:"/home/index3",

controller:'testController'})

}]);

3.使用路由跳转,结合ng-view做spa

3.1 在JS中使用$location进行跳转,如示例,在需要的时候调用goToIndex2即可

testModule.controller("testController", ["$scope", "$location", function($scope, $location) {

$scope.goToIndex2= function() {

$location.path("/2")

}

}]);

3.2 在html代码中使用href="#path"来进行跳转

Index1@Styles.Render("~/Content/css/base")

@Scripts.Render("~/script/base")

This is Index1

Index2

Index3

Index2

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。