【问题标题】:ui-router clear cache programmaticallyui-router 以编程方式清除缓存
【发布时间】:2015-07-31 04:36:39
【问题描述】:

当方向改变时,我有动态改变模板。

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

因此我需要缓存这两个视图,但仍然能够看到模板发生变化,我该如何实现呢?

    $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
      }
    });

【问题讨论】:

    标签: caching typescript angular-ui-router ionic


    【解决方案1】:

    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
          }
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多