角度路线不起作用

时间:2015-09-28 09:23:24

标签: javascript angularjs

Angular route对我不起作用..

我的JS:

'use strict';

// Declare app level module which depends on filters, and services
var chatApp = angular.module('myApp', ['ngRoute']);

// configure our routes
chatApp.config(function($routeProvider) {
    $routeProvider

        // route for the home page
        .when('/index', {
            templateUrl : 'index.html',
            controller  : 'mainCtrl'
        })

        // route for the about page
        .when('/chat', {
            templateUrl : 'views/chat.html',
            controller  : 'chatCtrl'
        })
        .otherwise({redirectTo: '/index'});
});

chatApp.controller('mainCtrl', function($scope) {
    // create a message to display in our view
    $scope.message = 'Everyone come and see how good I look!';
});

chatApp.controller('chatCtrl', function($scope) {
    // create a message to display in our view
    $scope.message = 'Everyone come and see how good I look!';
});

在Html中:

<html ng-app="myApp">

也添加了我的脚本。

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.6/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.6/angular-resource.min.js">
</script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.6/angular-route.min.js">
</script>
<script src="https://cdn.firebase.com/js/client/2.0.4/firebase.js"></script>
<script src="https://cdn.firebase.com/libs/angularfire/0.9.0/angularfire.min.js"></script>
<script src="scripts/app.js"></script>


URL : ...goaway-web/app/chat  Example what I am trying. 
goaway-web/app/index

重定向或直接输入网址时,它无效.. 请帮忙!!

1 个答案:

答案 0 :(得分:2)

尝试使用#。

示例: <a href="#/index">SOME_DETAIL</a>

请检查,您是否在ng-view

上实施了index.html