【问题标题】:what is the best way to include markdown in angular-meteor在 angular-meteor 中包含降价的最佳方法是什么
【发布时间】:2015-08-09 06:38:30
【问题描述】:
我想在我的模板中包含markdown 文本。
我正在使用angular-meteor,我看到了 2 个替代方案:
还有其他选择吗?它会起作用吗?哪个更好?
【问题讨论】:
标签:
angularjs
meteor
angular-meteor
【解决方案2】:
有一次我使用摊牌创建了自己的指令,但后来决定我想摆脱它,只使用 Meteor 已经附带的东西。
第一件事。我有一个名为meteorTemplates.html 的.html 文件。我只是将我使用的所有流星模板放在这里。我只有 2 个,而且它们很小。
无论如何。模板如下所示:
<template name="mdTemplate">
{{#markdown}}{{md}}{{/markdown}}
</template>
在我的控制器里面我有:
$scope.my.markdown = '#Markdown';
根据angular-meteor docs:
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>