当ui-sref改变时,href不会刷新

时间:2015-06-09 20:24:40

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

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

while

和背后的代码如下:

until

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

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

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

我认为dashboard.hive-project.profile()会触发一个刷新href但没有param的事件,但它不起作用。我尝试了很多可能性,但没有任何效果。试图像

那样触发angular指令中的事件
.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>

有什么想法来解决我的问题吗?

1 个答案:

答案 0 :(得分: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>