EmberJS - 无法从组件的“服务”中获取 属性

EmberJS - Not able to get property from "service' from Component

在我的 ember 应用程序中,我试图从服务中检索数据到组件,但出现错误:

TypeError: this.start.toggleProperty is not a function - 但是我有一个 属性 有服务。

这是我的组件 js :

从 'ember' 导入 Ember;

export default Ember.Component.extend({
    start: Ember.inject.service( ),
    message: null,
    actions: {
        pressMe() {
            this.start.toggleProperty('isOn'); //throws error
            // this.set('message',this.start.importantInfo( ));
            // Ember.log(this.start.isOn);
            console.log( "start is", this.start.isOn ); //undefined!?
        }
    }
});

这是我的服务 js:

从 'ember' 导入 Ember;

export default Ember.Service.extend({
    isOn: false,
    importantInfo( ){
        return "Important Info is " + this.get('isOn');
    }
});

我错过了什么吗?有人建议我正确的方法吗? 提前致谢。

答案是,

this.get('start').toggleProperty('isOn')

原因是,

Injected properties are lazy loaded; meaning the service will not be instantiated until the property is explicitly called. Therefore you need to access services in your component using the get function otherwise you might get an undefined.

参考:
https://guides.emberjs.com/v2.14.0/applications/services/#toc_accessing-services