2014-11-21 54 views
0

我正在考虑使用AngularJS完成一个完整的SPA应用程序,该应用程序可以下载初始请求中的所有视图代码,然后通过AJAX请求与服务器进行通信。AngularJS完整SPA应用程序

最大的好处是它看起来应用程序在本地运行。

缺点是,也许最初的请求应用程序可能需要2分钟才能加载,因为它会向服务器发出大约40个页面请求。

没有办法像使用某种ASP.Net MVC捆绑包一样在单个请求中下载所有应用程序视图?

回答

0

我做了类似的事情。我正在使用Asp.net MVC & WebApiAngularJS

我的第一个请求是MVC Action - >它返回一种主页面(包括bundle)。
当页面下载到客户端时,AngularJS开始进入并负责。

现在我的模板视图也通过Razor视图引擎呈现(因为我需要一个特殊的内部引擎来定位我的关联模板) - 我可以使用bundle和其他.net内的东西,而不是获取纯HTML。

现在使用这种模板可以是坏BOD。 我在这个过程中提出了关于我想让Razor视图引擎做什么的红线。
当您在项目中使用Razor views \ templates时,很容易误用AngularJS

0

您可以使用$ templateCache服务一次下载多个视图。在运行阶段,你可以定义它们的全部(其中一些)。

var myApp = angular.module('myApp', []); 
myApp.run(function($templateCache) { 
    $templateCache.put('template1.html', 'This is the content of the template 1'); 
    $templateCache.put('template2.html', 'This is the content of the template 2'); 
    $templateCache.put('template3.html', 'This is the content of the template 3'); 
});