简短的介绍:我将 AngularJs 与 Meteor+ Blade一起使用,而没有为流星使用Meteor_angularjs包。Blade 在服务器中构造页面的主体,然后我在客户端手动引导 angular。
Blade 下有可用的模板文件,Template['template_name']
因此它们可以轻松地在客户端上呈现。我想做类似的事情:
div(ng-include='content.blade')
// HTML => <div ng-include='content.blade'></div>
并以某种方式使其工作。
为了保持兼容性并且不创建新指令,我认为可以拦截 Angular 对静态模板的 XHR 请求并添加条件
if(URI ends with '.blade') then
name <- strip '.blade' in URI
return Template[name]()
哪个应该返回该模板的编译 HTML。
更新:
巧合的是,我遇到了 $templateCache,现在我认为这是要走的路。
我创建了一个 'ngMeteor' 模块,用于流星角积分。
angular.module 'ngMeteor',[], ->
throw 'Meteor object undefined.' unless Meteor? # Is it fine to put here?
angular.module('ngMeteor.blade',['ngMeteor']).
run ($templateCache) ->
$templateCache.put "#{name}.blade", render() for own name, render of Template
在我的应用程序中:
angular.element(document).ready ->
angular.bootstrap document, ['app']
app = angular.module 'app', ['ngMeteor.blade'], ->
app.controller 'mainCtrl', ($scope,$templateCache) ->
$scope.content = $templateCache.get "content.blade" # Works!!
刀片(body.blade):
#main(ng-controller='mainCtrl') {{ content }}
现在它可以工作了,我可以在注入 $templateCache 并通过其名称获取模板后从控制器获取呈现的模板,但ng-include
仍然无法正常工作。