我尝试在我的适配器中注入服务,但收到此错误:“Assert失败:尝试在没有容器的对象上查找插入的属性,请确保该对象已通过容器示例化。”
有人能告诉我如何在适配器中注入服务吗?
//services/api.js
import AjaxService from 'ember-ajax/services/ajax';
import ENV from 'nfe-customer-console-v2/config/environment';
import { inject as service } from '@ember/service';
import { computed } from '@ember/object';
export default AjaxService.extend({
session: service(),
host: ENV.APP.API_URL,
headers: computed('session.authToken', {
get() {
let headers = {};
const authToken = this.get('session.data.authenticated.access_token');
if (authToken) {
headers['Authorization'] = `Bearer ${authToken}`;
}
return headers;
}
})
});
//adapters/conta.js
import EmberObject from '@ember/object';
import {inject as service} from '@ember/service';
export default EmberObject.extend({
api: service(),
changePassword(model) {
return this.get('api').request('/users/change_password', {
method: 'POST',
data: {
oldPassword: model.oldPassword,
newPassword: model.newPassword,
confirmPassword: model.confirmPassword
},
})
}
})
Error: "Assertion Failed: Attempting to lookup an injected property on an object without a container, ensure that the object was instantiated via a container."
1条答案
按热度按时间7d7tgy0s1#
您可以使用初始设定式来插入工作阶段。例如,使用'ember-simple-auth':