gpt4 book ai didi

angularjs - 用户界面路由器 : A route with no view template

转载 作者:行者123 更新时间:2023-12-02 21:41:35 26 4
gpt4 key购买 nike

是否可以在只有 Controller 的 ui-router 中设置路由?目的是在某个 URL 上,我唯一想做的是以编程方式执行操作,而不是在 View 中显示任何内容。我已经阅读了文档,但我不确定他们是否提供了一种方法来做到这一点。

是的,我已经读过:https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-open-a-dialogmodal-at-a-certain-state ,但这并不是我想要的。

例如,假设我有一个带有 View 的基本主体:

<body ui-view></body>

还有一些基本配置:

// Routes
$stateProvider
.state('myaction', {
url: "/go/myaction",
onEnter: function() {
console.log('doing something');
}
});

当访问 /go/myaction 时, View 为空白。可以这样做吗?

最佳答案

我能够通过将我正在执行编程操作的 headless 状态重定向到 headless 状态末尾具有 View 的状态来解决此问题:

$stateProvider
.state('myaction', {
url: "/go/myaction",
onEnter: function() {
console.log('doing something');
}
controller: function($state) {
$state.go('home');
}
});

关于angularjs - 用户界面路由器 : A route with no view template,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19171655/

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