【发布时间】:2014-07-15 01:51:57
【问题描述】:
当我尝试更改控制器中的位置时,它会加载服务器的根目录,而不是特定页面:
'use strict';
eventsApp.controller('TestController',
function TestController($scope, $location){
console.log('test comes here!');
$scope.makeTest = function(){
$location.url('/test');
}
});
我有一个这样的路由器:
'use strict';
var eventsApp = angular.module('eventsApp', ['ngResource','ngSanitize'])
.config(function($routeProvider, $locationProvider){
$routeProvider
.when('/test',{
templateUrl:'templates/test.html',
controller:'TestController'
}).otherwise({
templateUrl:'templates/default.html',
controller:'DefaultController',
redirectTo:''
});
$locationProvider.html5Mode(true);
});
在我的 index.html 中我设置了指令
<base href="/">
似乎每次它都实现否则。但是,如果我使用
location.href = '/test';
而不是
$location.url('/test');
,然后就可以了。 我不知道这种行为。你呢?
【问题讨论】:
-
你需要使用
$scope.$apply()见stackoverflow.com/questions/11784656/… -
我之前尝试过这样做。它告诉我:错误:$apply 已经在进行中
标签: routing location directive