在角度流星中包含降价的最佳方法是什么?

时间:2015-05-27 09:13:17

标签: angularjs meteor angular-meteor

我想在我的模板中加入markdown文字。 我正在使用angular-meteor,我看到了两个替代方案:

  • 安装角度包,例如angular-markdown-directive
  • 包含没有.ng.html后缀的文件,并按照以下方式使用meteor的降价:{{#markdown}}{{>innerPreview}}{{/markdown}}

还有其他选择吗?它会起作用吗?哪个更好?

2 个答案:

答案 0 :(得分:2)

我在hypercube's package的氛围中创建了包oshai:angular-marked。你可以在大气中搜索它。

答案 1 :(得分:1)

有一次我使用showdown创建了我自己的指令,但后来决定我想摆脱它并且只使用Meteor已经带来的。

第一件事。我有一个名为meteorTemplates.html的.html文件。我只是将所有的流星模板放在我使用的地方。我只有2,而且他们很小。

无论如何。模板看起来像这样:

<template name="mdTemplate">
    {{#markdown}}{{md}}{{/markdown}}
</template>

我的控制器里面有:

$scope.my.markdown = '#Markdown';

根据angular-meteor文档:

The meteor-include directive holds the Angular scope of the directive as the as Template.currentData of the Meteor template.

所以,Template.currentData == $ scope。

然后在模板帮助器中,我将像$ scope一样使用Template.currentData()。

Template.mdTemplate.helpers({
    md: function() {
      return Template.currentData().getReactively('my.markdown');
    }
});

我的ng.html文件如下所示:

<div id="markdown-preview">
    <meteor-include src="mdTemplate"></meteor-include>
</div>
相关问题