使用 ember 设置 Web 应用程序索引页的标题

Setting title of a web application's index page using ember

我想动态更新我的 Web 应用程序的标题并在其后附加用户名。我知道这可以使用 jquery 来完成,但想知道是否有任何 ember 方法可以做到这一点。

我在 app/index.html 中的标题看起来像这样

<title>XYZ.com</title>

但我想让它看起来像

<title>XYZ.com - User name</title>

并且用户名来自 ember 模型 User.name


document.title = "test";

希望对你有所帮助

在应用程序控制器中声明一个变量。

webName: null

还有哪个地方你要改web应用名你修改application controller的controller变量

this.controllerFor('application').set('webName', yourwebappname);

为此有一个 Ember CLI 插件。

使用 'ember-cli-document-title' 以一种理智的方式管理您的文档标题。

自述文件有很好的使用说明。

Link 到插件https://github.com/kimroen/ember-cli-document-title