什么是最好的地方,把文本常量在角



我有一个angular项目,想设置一个文本常量

article_sample = "<h1> This is a sample article </h1>
      This is the content
      This is the content
      This is the content
      ...
      This is the content"

这个article_sample很长(可能超过一页)。在我的js文件,我应该使用分配article_sample,如果我得到null文章从后端:

if (article == null) {
    article = article_sample;
}

我不想把常量或变量article_sample放在同一个js文件中,因为它会占用文件的很大一部分,使其不可读。

那么把这个常量(或变量)放在哪里最好呢?

您可以使用以下代码将此常量放入app.js或任何其他文件

angular.module('myApp', []).constant('ARTICLE_SAMPLE', '<h1>This is a sample .....');

来自文档:

<标题>常数(名称、对象),

因为常量是固定的,所以它们得到在其他提供方法之前应用。看到美元provide.constant () .

最新更新