【问题标题】:The href doesn't refresh when the ui-sref changes当 ui-sref 更改时,href 不会刷新
【发布时间】:2015-06-09 20:24:39
【问题描述】:

我有角度问题。我的模板中有这段代码:

<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 但没有参数的事件,它不起作用。我尝试了很多可能性,但没有任何效果。试图在这样的角度指令中触发事件

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

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

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

【问题讨论】:

    标签: javascript angularjs angularjs-directive angular-ui-router interpolation-directive


    【解决方案1】:

    我认为您不能在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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-29
      • 1970-01-01
      • 1970-01-01
      • 2017-02-13
      相关资源
      最近更新 更多