在angularjs materialdesign中路由

时间:2015-04-25 13:59:54

标签: angularjs material-design

我试图找出如何在angularjs材料设计中的页面之间进行路由。

在此示例中,我想在单击侧边栏链接时更改页面 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>

1 个答案:

答案 0 :(得分:4)

您是否尝试将href属性放入标记<a>

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

这样,每当AngularJS看到网址更改时,它都会触发路由器查找指定的路径。