gpt4 book ai didi

javascript - ui-sref 更改时 href 不会刷新

转载 作者:行者123 更新时间:2023-11-28 00:12:49 26 4
gpt4 key购买 nike

我对 Angular 有疑问。我的模板中有此代码:

<select class="form-control"
ng-model="hiveReports.reportSelected"
ng-options="link for link in hiveReports.reportsLink"
ui-sref="dashboard.hive-reports.{{hiveReports.reportSelected}}">
</select>

背后的代码如下:

.config(['$stateProvider', function ($stateProvider) {
$stateProvider
.state('dashboard.hive-reports', {
url: '/hive-reports',
template: require('./hiveReports.tmpl.html'),
abstract: true,
controller: 'HiveReportsCtrl as hiveReports'
});
}])
.controller('HiveReportsCtrl', [
'$rootScope',
'$state',
function ($rootScope,
$state) {

var controller = this;
controller.reportSelected = 'transactions';
controller.reportsLink = ['transactions','devices'];
}])

当我选择一个选项时,它会创建一个选择并切换状态。

在另一个模板中,它工作正常,但我在链接中有一个像这样的参数

<select class="form-control"
ng-model="hiveProfile.selectedProfile "
ng-options="profile.id as profile.name for profile in hiveProfile.profile"
ui-sref="dashboard.hive-profile.profile({profileId:hiveProfile.selectedProfile })">
</select>

我认为dashboard.hive-project.profile()触发了一个刷新href的事件,但没有参数,它不起作用。我尝试了很多可能性,但没有任何作用。尝试在像这样的 Angular Directive(指令)中触发事件

ui-sref="dashboard.hive-reports.{{hiveReports.reportSelected}}()">

ui-sref="dashboard.hive-reports.{{hiveReports.reportSelected}}({})">

有什么办法可以解决我的问题吗?

最佳答案

我认为您不能使用像 ui-sref 中那样的模板标签。我认为您需要创建一个状态并传递动态 reportSelected 就像您对配置文件所做的那样。

$stateProvider
.state('dashboard.hive-reports', {
url: '/hive-reports',
template: require('./hiveReports.tmpl.html'),
abstract: true,
controller: 'HiveReportsCtrl as hiveReports'
})
.state('dashboard.hive-reports.report', {
url: '/{report}',
template: require('./hiveReportsReport.tmpl.html'),
controller: 'HiveReportsReportCtrl as hiveReportsReport'
});

<select class="form-control"
ng-model="hiveReports.reportSelected"
ng-options="link for link in hiveReports.reportsLink"
ui-sref="dashboard.hive-reports.report({report: hiveReports.reportSelected})">
</select>

关于javascript - ui-sref 更改时 href 不会刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30742138/

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