2015-05-29 71 views
0

我用一个配置路由:为什么我的路由不能在Angular JS中使用URL?

.config(['$routeProvider', 
      function($routeProvider) { 
       $routeProvider 
        .when('/appointments', { 
         controller: 'AppointmentController' 
        }) 
    }]) 

和控制器:

.controller('AppointmentController', ['$scope', '$http', '$sce', function ($scope, $http, $sce) { 
    alert('Test') 
}]); 

链接看起来像为:http://blogapp.com/appointments

所以,我没有网页上的错误,但alert()不当我输入URL时工作

+1

尝试使用'http://blogapp.com/appointments '(最后加上“s”) –

+0

对不起,有一个错字。我有's'的网址 – Faud

+0

不能,因为我在PHP /约会页面 – Faud

回答

0

试试去

http://blogapp.com/#/appointments 

对于Angular,默认情况下将包含散列。

0

正如亚瑟评论,你就需要去http://blogapp.com/#/appointments

要停止这一点,并删除#,替换为您的配置:

.config(['$routeProvider', '$locationProvider', 
      function($routeProvider, $locationProvider) { 
       $routeProvider 
        .when('/appointments', { 
         controller: 'AppointmentController' 
        }) 

$locationProvider.html5Mode(true); 

    }]) 
+0

我喜欢你提供的,那么PHP的其他URL将不起作用 – Faud

相关问题