-1

嗨,我正在从事具有五步形式的项目,并且有大约 10 ng-repeat 的 json 值。我有时会遇到性能问题,因为 ng-repeat 是空的,所以我的字段没有显示任何值,但是当我刷新浏览器时它再次工作,我正在使用 ui.router。我该如何解决这个问题请帮忙。无论如何可以确保加载所有值。

4

1 回答 1

0

使用resolveangular ui-router 的参数确保在控制器实例化之前数据可用。

https://github.com/angular-ui/ui-router/wiki向下滚动到该resolve部分。

编辑:对于您的特定用例...

$stateProvider.state('wsp.first_step', 
  { 
    url: '/first_step', 
    templateUrl: 'wsp_edit_step_first',
    resolve: {
      jsonData: function() { //jsonData can be injected into controller
        return /* insert json objects here */;  
      }
    }
  }).state('wsp.second_step', 
  { 
    url: '/second_step', 
    templateUrl: 'wsp_edit_step_second',
    resolve: {
      jsonData2: function() { //jsonData2 can be injected into controller
        return /* insert json objects here */;  
      }
    } 
  }) 
  $urlRouterProvider.otherwise('/wsp/first_step')
于 2016-09-27T19:30:10.513 回答