gpt4 book ai didi

javascript - $location.path ("/");不能正常工作

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:44:03 24 4
gpt4 key购买 nike

当我尝试使用 $location.path() 时,url 发生了变化,但是我在 .path 中传递的任何内容都会附加到我当前的 url。我希望当我执行 addShow() 时,我想转到我的主页 index.html。能否请你帮忙。url 变化如下: http://localhost:8080/add当我执行我的 addShow 函数时,它变为: http://localhost:8080/add#/我想让它转到我的主页。

angular.module('app').controller("MainController",['$location', function($location) {
var vm = this;
vm.title = 'TV Show';
vm.searchInput = '';
vm.shows = [{
title: 'Game of Thrones',
year: 2011,
favorite: true
}, {
title: 'Walking Dead',
year: 2010,
favorite: false
}, {
title: 'Firefly',
year: 2002,
favorite: true
}, {
title: 'Banshee',
year: 2013,
favorite: true
}, {
title: 'Greys Anatomy',
year: 2005,
favorite: false
}];
vm.orders = [{
id: 1,
title: 'Year Ascending',
key: 'year',
reverse: false
}, {
id: 2,
title: 'Year Descending',
key: 'year',
reverse: true
}, {
id: 3,
title: 'Title Ascending',
key: 'title',
reverse: false
}, {
id: 4,
title: 'Title Descending',
key: 'title',
reverse: true
}];
vm.order = vm.orders[0];
vm.new = {};
vm.addShow = function() {
vm.shows.push(vm.new);
console.log(vm.shows);
vm.new = {};
$location.path("/");
};

}]);

我的配置函数如下:

    (function() {

"use strict";

angular
.module("app")
.config(function($routeProvider, $locationProvider) {


//$locationProvider.html5Mode(true);

$routeProvider
.when('/', {
templateUrl: 'list.html',
controller: 'MainController',
controllerAs: 'main',
})
.when('/add', {
templateUrl: 'add.html',
controller: 'MainController',
controllerAs: 'main',
})
;

});
})();

最佳答案

尝试将 $location.path("/"); 替换为 $window.location.href = "/";

关于javascript - $location.path ("/");不能正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34012071/

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