问题
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