ui-router以编程方式清除缓存

时间:2015-05-19 11:17:29

标签: caching typescript angular-ui-router ionic

我在方向发生变化时动态更改模板。

出于这个原因,我禁用了缓存,但即使是功能非常强大的设备也非常慢。

出于这个原因,我需要缓存两个视图,但仍然可以看到模板更改,我该如何实现?

    $stateProvider.state("app.timesheet", {
      cache: false,
      url: "/timesheet",
      views: {
        "menuContent": {
          templateUrl: () => {
            var orientation: number = ( < any > window).orientation;
            if (orientation === 90 || orientation === -90) { // Landscape
              return "views/timesheet/landscape.html"
            } else if (orientation === 0 || orientation === 180 || orientation === -180) { // Portrait
              return "views/timesheet/portrait.html";
            }
          },
          controller: "TimesheetController"
        }
      },
      data: {
        requireAuthorize: true
      }
    });

1 个答案:

答案 0 :(得分:0)

templateUrl可以是一个函数。并在该函数中还添加“else”块以返回默认模板。如下所示:

$stateProvider.state("app.timesheet", {
      url: "/timesheet",
      views: {
        "menuContent": {
          templateUrl: function() {
            var orientation: number = ( < any > window).orientation;
            if (orientation === 90 || orientation === -90) { // Landscape
              return "views/timesheet/landscape.html"
            } else if (orientation === 0 || orientation === 180 || orientation === -180) { // Portrait
              return "views/timesheet/portrait.html";
            }else {
               //return default template
            }
          },
          controller: "TimesheetController"
        }
      },
      data: {
        requireAuthorize: true
      }
    });