Reputation: 136
I am currently facing an issue with computed properties, I have a model named crossconnection containing some computed properties like :
relevantPoints: computed(function () {
if (this.get('IsCA') === true && this.get('IsCM') === true) {
return "/assets/images/big/ca-cm.png";
}
else if (this.get('IsCA') === true && this.get('IsCM') === false) {
return "/assets/images/big/ca.png";
}
else if (this.get('IsCA') === false && this.get('IsCM') === true) {
return "/assets/images/big/cm.png";
}
else if (this.get('IsCA') === false && this.get('IsCM') === false) {
return "/assets/images/big/nca-ncm.png";
}
}),
when running the project I keep getting the following error :
Uncaught TypeError: Cannot call a class as a function
Can somebody please clarify ?
PS : I am using,
Update :
Clarifications : I have a model 'crossconnection ' that contains some computed properties, my model is called from the controller via a simple
from = this.store.query('crossconnection ', {
fromOpKey: this.get('opSelected').get('opKey'),
limit: -1
});
Which then causes the following error (full stack trace attached)
Uncaught TypeError: Cannot call a class as a function
at classCallCheck (ember-babel.js:11)
at Object.Class [as Object] (core_object.js:25)
at Module.callback (crossconnection.js:65)
at Module.exports (loader.js:106)
at requireModule (loader.js:27)
at Class._extractDefaultExport (index.js:410)
at Class.resolveOther (index.js:110)
at Class.superWrapper [as resolveOther] (ember-utils.js:420)
at Class.resolve (resolver.js:133)
at _resolve (container.js:871)
classCallCheck @ ember-babel.js:11
Class @ core_object.js:25
(anonymous) @ crossconnection.js:65
Module.exports @ loader.js:106
requireModule @ loader.js:27
_extractDefaultExport @ index.js:410
resolveOther @ index.js:110
superWrapper @ ember-utils.js:420
resolve @ resolver.js:133
_resolve @ container.js:871
resolve @ container.js:574
resolve @ container.js:578
factoryFor @ container.js:136
factoryFor @ container_proxy.js:40
modelFactoryFor @ -private.js:11593
_modelFactoryFor @ -private.js:11556
_modelFor @ -private.js:11547
modelFor @ -private.js:11540
_query @ -private.js:8666
_query @ -private.js:10819
query @ -private.js:10806
(anonymous) @ ops.js:55
applyStr @ ember-utils.js:524
sendEvent @ ember-metal.js:257
notifyObservers @ ember-metal.js:1103
propertyDidChange @ ember-metal.js:886
set @ ember-metal.js:2893
set @ observable.js:104
openOpPopupWithKey @ ops.js:143
send @ action_handler.js:28
(anonymous) @ action.js:124
exports.flaggedInstrument @ ember-metal.js:3920
(anonymous) @ action.js:123
_run @ backburner.js:758
_join @ backburner.js:736
join @ backburner.js:477
run.join @ ember-metal.js:4366
handler @ action.js:102
(anonymous) @ event_dispatcher.js:234
dispatch @ jquery.js:5183
elemData.handle @ jquery.js:4991
Upvotes: 0
Views: 1373
Reputation: 1015
Please make sure you import computed
correctly:
import { computed } from '@ember/object';
Upvotes: 6
Reputation: 2276
Edit - this doesn’t seem to be the cause of the error, but I’ll leave it here for now
You are missing an argument in your computed. Computed takes first the attributes to watch as strings, and then the callback function:
relevantPoints: computed(‘isCA’, ‘isCM’, function () {
if (this.get('IsCA') === true && this.get('IsCM') === true) {
return "/assets/images/big/ca-cm.png";
}
...,
}),
This answer applies to 1.13 through 3.x, with one small modification to the code snippets for < 3.0. App versions less than 3.0 should do Ember.computed instead of computed.
Upvotes: 1