gpt4 book ai didi

angularjs - AngularJS MaterialDesign 中的路由

转载 作者:行者123 更新时间:2023-12-02 23:33:01 25 4
gpt4 key购买 nike

我试图弄清楚如何在 AngularJS Material 设计中的页面之间进行路由。

在此示例中,我想在单击侧边栏链接时更改页面 http://codepen.io/kyleledbetter/pen/gbQOaV

Script.js

// script.js

// create the module and name it scotchApp
// also include ngRoute for all our routing needs
var starterApp = angular.module('starterApp', ['ngRoute']);

// configure our routes
starterApp.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
starterApp.controller('mainController', function($scope) {
// create a message to display in our view
$scope.message = 'Everyone come and see how good I look!';
});

starterApp.controller('aboutController', function($scope) {
$scope.message = 'Look! I am an about page.';
});

starterApp.controller('contactController', function($scope) {
$scope.message = 'Contact us! JK. This is just a demo.';
});

about.html

<div class="jumbotron text-center">
<h1>About Page</h1>

<p>{{ message }}</p>
</div>

最佳答案

您是否尝试过将 href 属性放入标签 <a> 中?

<a href="#/">Home</a>
<a href="#/about">About</a>
<a href="#/contact">Contact</a>

这样,每当 AngularJS 看到 url 发生变化时,它就会触发路由器查找指定的路径。

关于angularjs - AngularJS MaterialDesign 中的路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29866119/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com