1

我想将markdown文本作为模板的一部分。我正在使用angular-meteor,我看到了 2 个替代方案:

  • 安装一个角度包,例如angular-markdown-directive
  • 包含一个没有.ng.html后缀的文件,并像这样使用流星的降价:{{#markdown}}{{>innerPreview}}{{/markdown}}

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

4

2 回答 2

2

我从超立方体的包oshai:angular-marked中创建了大气中的包。你可以在大气中搜索它。

于 2015-05-28T12:26:06.113 回答
1

有一次,我使用摊牌创建了自己的指令,但后来决定我想摆脱它,只使用 Meteor 已经附带的东西。

第一件事。我有一个我调用的 .html 文件meteorTemplates.html。我只是将我使用的所有流星模板放在这里。我只有2个而且它们很小。

任何状况之下。模板如下所示:

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

在我的控制器内部,我有:

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

根据角流星文档:

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

所以,Template.currentData == $scope。

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

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

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

<div id="markdown-preview">
    <meteor-include src="mdTemplate"></meteor-include>
</div>
于 2015-07-15T21:06:43.863 回答