1

简短的介绍:我将 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仍然无法正常工作。

4

1 回答 1

0

我之前对问题的更新实际上是正确的答案,ngInclude 对我不起作用,因为div(ng-include="'content.blade'")......是的,内部引号!这就像我第 N 次遇到这个问题。
在简历中,答案是:

angular.module('blade').
  run ($templateCache) ->
    $templateCache.put "#{name}.blade", render() for own name, render of Template

模板是流星全局变量,刀片将存储准备渲染的模板,然后使用 $templateCache 我将渲染的模板与相应的名称/ID 放在一起,这样 Angular 就可以使用它们。
编辑:基于这个问题,我创建了一个流星包ng-meteor用于流星中的无支架角度发展。

于 2013-02-05T17:27:26.793 回答