AngularJS $templateCache under MVC

假装没事ソ 提交于 2019-12-13 08:45:56

问题


I couldn't find any documentation or article on this.
We here at the company I work for have MVC project.
And we build Angular SPA on top of it.
Also we want it to work offline.
So, I need cache. Found $templateCache module in AngularJS.
And trying to implement it. Since the project is MVC, all the templates I want to load into ng-view are actually MVC partial views and I can load them by calling {Controller}/{Action}.
But the are no examples on internet ho to implement $templateCache in this case.
All the examples show how to use static templates, like mytemplate.html or just strings. This won't work under MVC.
So, I was trying to figure out how to accomplish that, wrote this, for app.ts:

namespace AppDomain {
"use strict";

export let app = angular.module("app", ["ngRoute"]);

app.config(function ($routeProvider) {
    $routeProvider
        .when("/", { templateUrl: "Home/Template?name=Main", controller: "Controller", controllerAs: "vm" })
        .when("/About", { templateUrl: "Home/Template?name=About", controller: "Controller", controllerAs: "vm" })
        .when("/Contact", { templateUrl: "Home/Template?name=Contact", controller: "Controller", controllerAs: "vm" })
        .otherwise({ redirectTo: "/" });
});

app.run(function ($templateCache) {
    $templateCache.put("Home/Template?name=Main", "Home/Template?name=Main");
    $templateCache.put("Home/Template?name=About", "Home/Template?name=About");
    $templateCache.put("Home/Template?name=Contact", "Home/Template?name=Contact");
});

}

Obviously this doesnt work. Any suggestions? Thanks.

来源:https://stackoverflow.com/questions/39418596/angularjs-templatecache-under-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!