Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ember.js 如果ApplicationController由Ember自动初始化,如何将控制器中的属性绑定到应用程序控制器?_Ember.js - Fatal编程技术网

Ember.js 如果ApplicationController由Ember自动初始化,如何将控制器中的属性绑定到应用程序控制器?

Ember.js 如果ApplicationController由Ember自动初始化,如何将控制器中的属性绑定到应用程序控制器?,ember.js,Ember.js,我的Ember controller中有一个属性,我想将其绑定到application controller中的一个属性,但由于我没有创建ApplicationController的实例,因此我无法提供引用。大概 MyApp.ApplicationController = Em.Controller.extend({ userName: 'hohenhiem' }); MyApp.SampleController = Em.Controller.extend({ nameBin

我的Ember controller中有一个属性,我想将其绑定到application controller中的一个属性,但由于我没有创建ApplicationController的实例,因此我无法提供引用。大概

MyApp.ApplicationController = Em.Controller.extend({
    userName: 'hohenhiem'
});

MyApp.SampleController = Em.Controller.extend({
    nameBinding: 'application.userName'
});

我有一个问题要解决

您正在寻找需求属性。在控制器中,可以指定依赖项,然后按如下方式使用它们:

MyApp.SampleController = Em.Controller.extend({
    needs: ['application'],
    nameBinding: 'controllers.application.userName' });

您正在查找需求属性。在控制器中,可以指定依赖项,然后按如下方式使用它们:

MyApp.SampleController = Em.Controller.extend({
    needs: ['application'],
    nameBinding: 'controllers.application.userName' });

非常感谢。很长一段时间以来这一直困扰着我。非常感谢。这一直困扰着我。