ember.js - {{content-for 'head'}} Ember-cli

标签 ember.js ember-cli

在过去的1个月里,我一直在使用Yeoman ember generator,现在,我想尝试一下ember-cli。

我运行发电机并启动应用程序,一切正常。

ember new my-new-app
ember server

但我想知道如何
{{content-for 'head'}}

在app / index.html中工作吗?

当查看http://www.ember-cli.com/#tutorials的其他示例时,没有人使用这个特定的帮助程序吗?是因为他们使用的是ember-cli的旧版本吗?他们为什么不使用此内容帮助器?

我很确定ember.js缺省没有此内容(用于帮助程序),所以我猜ember-cli在某个地方写了它?它在哪里,做什么用的?

另外,当我检查my-new-app页面的元素时,“Welcome to Ember.js”的div标 checkout 现在body标签而不是head标签上了吗?那怎么可能? {{mind-blown}}

(在app / index.html中,{{content-for'head'}}被放置在head标签内)

最佳答案

最近已将其添加到基于this discussion的ember-cli中。

这是commit的相关代码:

EmberApp.prototype.contentFor = function(config, match, type) {
  var content = [];

  if (type === 'head') {
    content.push(calculateBaseTag(config));

    content.push('<meta name="' + config.modulePrefix + '/config/environment" ' +
                 'content="' + escape(JSON.stringify(config)) + '">');
  }

  content = this.project.addons.reduce(function(content, addon) {
    if (addon.contentFor) {
      return content.concat(addon.contentFor(type, config));
    }

    return content;
  }, content);

  return content.join('\n');
};

关于ember.js - {{content-for 'head'}} Ember-cli,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26210367/

相关文章:

javascript - 使用 ember.js 2.0 的 ember cli 应用程序基础

javascript - session 后访问 session 用户名如何在其他 Controller 中进行身份验证

ember.js - EMBERJS : How to trigger an action in a child component?

ember.js - 覆盖 DS.Store ember-cli

javascript - Ember : WillTransition does not fire when going directly to URL

node.js - 实时重新加载无法与 ember-cli 一起使用

javascript - 无法在 Ember 中填充 Object.fromEntries

javascript - 在 Ember 中创建和更新嵌套对象

javascript - 如何在一对多关系中创建对象

ember.js - 测试 Ember 数据模型-找不到关系