Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to 0.9, now getting t.choices is not a function #778

Closed
OverZealous opened this issue Nov 12, 2015 · 16 comments
Closed

Updated to 0.9, now getting t.choices is not a function #778

OverZealous opened this issue Nov 12, 2015 · 16 comments

Comments

@OverZealous
Copy link

Every time I switch to an edit page, I'm now getting this error:

Error: t.choices is not a function
r/<.compile/<.pre@http://localhost:3001/adm/js/vendor/ng-admin/build/ng-admin.min.js:15:2543

«snipped Angular call stack »

 <ma-choice-field class="ng-isolate-scope" field="::field" entry="entry" value="value">

I've narrowed it down to line 36 of maChoiceField.js. I don't know exactly what's wrong. I think it's a mistake, because it calls the function then uses the result.

Looks like the change was made in commit 0f06936.

If it matters, these fields are using a custom function for the choices. It's a bit of a hack to allow me to asynchronously load some meta data from the server, but it shouldn't affect anything. The way it works is like this:

let someChoices = [];
app.config(function(...) {
    field.choices(() => someChoices);
});

...

app.run(function ($http) {
    // load remote values
    someChoices = remoteValues;
});

I'd make a minimal test case, but I'm honestly trying to figure out how to do that, since you need a RESTful backend.

@OverZealous OverZealous changed the title Updated to 0.9, not getting t.choices is not a function Updated to 0.9, now getting t.choices is not a function Nov 12, 2015
OverZealous added a commit to OverZealous/ng-admin that referenced this issue Nov 12, 2015
@fzaninotto
Copy link
Member

I really wonder about your error. I've never seen it myself. And it seems that it doesn't set a & directive attribute as a function... Which Angular version are you using?

@OverZealous
Copy link
Author

Angular 1.4.5. What you said in the PR makes sense, but I definitely got that error consistently. I'll try upgrading again later today.

@OverZealous
Copy link
Author

BTW: I didn't think foo: '&?' was a valid use for optional expressions. It seems like a mistake to be overriding the passed in expression in the scope property like that.

@fzaninotto
Copy link
Member

Why is it a mistake?

@fzaninotto
Copy link
Member

Angular 1.4.5

That's why. ng-admin is tested on angular 1.3. Migration to 1.4 is not yet started (cf #567)

@OverZealous
Copy link
Author

Because it's a function created on the scope to call back the expression, and it's being overridden with a static property, breaking the binding. It makes the logic harder to follow, too, because it switches from a function to an array at some point.


Really? I thought I just read that v0.9 was going to be the switch to ng 1.4, since 0.8 was the last to support 1.3.x.

That sucks for me. 😦

@OverZealous
Copy link
Author

OK, this fix worked for me on Angular 1.4.7:

var choices = (angular.isFunction(scope.choices) && scope.choices()) ? scope.choices : (field.choices ? field.choices() : [])

@fzaninotto
Copy link
Member

That still doesn't make sense. Does the following work?

var choices = (typeof scope.choices == 'function' && scope.choices()) ? scope.choices() : (field.choices ? field.choices() : []);

0.8 was supposed to be the latest version built on Angular 1.3, but we packed too many features in 0.9 not to release it before breaking compatibility. You'll have to wait a bit for 1.4 compatibility.

@fzaninotto
Copy link
Member

Note: I tracked down the BC Break in Angular 1.4 to this commit: angular/angular.js@6a38dbf

@OverZealous
Copy link
Author

Yup, looks like that's the change.

The code from above is almost the same thing as mine, I'm just using Angular's built-in isFunction, rather than typeof. I assume it would work the same.

The other difference is you are calling scope.choices() for the assignment, which is different than the existing code, which looks more like mine:

// existing code
var choices = scope.choices() ? scope.choices : (field.choices ? field.choices() : []);

@OverZealous
Copy link
Author

Thank you, sir! :-)

@KonstantinYegupov
Copy link

This fix is not yet added to built files and cannot be easily installed via Bower, I presume?..

@fzaninotto
Copy link
Member

It is added to built files. To get it from bower, you must reference the master branch (see http://stackoverflow.com/a/16951315 for directions).

@KonstantinYegupov
Copy link

I've tried and that didn't work - built files were updated 20 days ago and the fix was added 19 days ago...

@fzaninotto
Copy link
Member

It should be fixed by now, I've published a new build a couple days ago.

@mikeplavo
Copy link

I'm reading the documentation (Getting-started chapter) and i have the same error when i tried to display the users filter in the post listview section.

I am using angularjs 1.5.0
Should have I to wait a bit for a 1.5 compatibility ?

Edit: I have this bug too with angularjs 1.4.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants