Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Typehead broken when using promises in Angularjs 1.2.0rc2 #949

Closed
overloadnn opened this issue Sep 5, 2013 · 21 comments
Closed

Typehead broken when using promises in Angularjs 1.2.0rc2 #949

overloadnn opened this issue Sep 5, 2013 · 21 comments

Comments

@overloadnn
Copy link

On search, I get a "Error: matches is undefined" exception.

@pkozlowski-opensource
Copy link
Member

@overloadnn http://plnkr.co/, please

@vpixle
Copy link

vpixle commented Sep 5, 2013

The problem may not necessarily be related to promises but typeahead itself
Here is the Plunk copy of the demo site with Angular 1.2.0rc1
http://plnkr.co/edit/VPk5mZy6mx4GwatULIja

@pkozlowski-opensource
Copy link
Member

@vpixle what you see is duplicate of #813 and is already fixed in master via 7589339.

@overloadnn do you have other reproduce scenario?

@vpixle
Copy link

vpixle commented Sep 5, 2013

Pawel, give me a second to test it. I have just downloaded a "NEW" version from a http://angular-ui.github.io/bootstrap/ where is a jumbotron loadbutton that points to https://github.com/angular-ui/bootstrap/tree/gh-pages page that is featuring a month old ui-bootstrap-tpls-0.5.0.min.js

IMHO the https://github.com/angular-ui/bootstrap/tree/gh-pages should be blocked or at least the 0.5.0 file 2B deleted.

@overloadnn
Copy link
Author

http://plnkr.co/edit/SXcZXTemPWz3snIUniwb

Switch between versions of angular in index.html and you'll see.

@countableSet
Copy link

Here's the commit from angular which broke using promise with typeahead:
angular/angular.js@3a65822

The error: TypeError: Cannot read property 'length' of undefined
From this line: https://github.com/angular-ui/bootstrap/blob/master/src/typeahead/typeahead.js#L104

@pkozlowski-opensource
Copy link
Member

@countableSet thnx for looking into this! Indeed, seems like $parse unwraps promises now without exposing it :-( I'm not sure how to fix it atm, will have to discuss with the AngularJS team.

@wilsonjackson
Copy link

For anyone else affected by this, here's the dirty hack I came up with to work around the issue until a real solution is found:

$scope.functionThatReturnsAPromise = function () {
  var promise = $http.post(...);
  promise.$$v = promise;
  return promise;
};

$parse will unwrap any promise and load its eventual resolution value into $$v, but if you set your own $$v it will leave it alone. Obviously not good for the long term, but it's getting me by for now.

@overloadnn
Copy link
Author

@wilsonjackson I came up with the same solution. This, however, breaks the angular change that was made for watching function changes:
Try this with / without the $$v patch:

$scope.$watch('functionThatReturnsAPromise', function (newValue, oldValue) {
        debugger;
    });

@frapontillo
Copy link

I can confirm this, I have the same issue while returning a $promise from a $resource call. Going back to 1.2.0-rc.1 fixes this.

@pkozlowski-opensource
Copy link
Member

Yeh, RC2 broken several things pretty bad... I really need to discuss this issue with the core team as for now I don't see any straightforward solution. The work-around proposed by @wilsonjackson is the best we've got for now.

guillaume86 referenced this issue in angular/angular.js Sep 11, 2013
When a parsed function call returns a promise, the evaluated value
is the resolved value of the promise rather than the promise object.

Closes #3503
@muehle
Copy link

muehle commented Sep 12, 2013

wilsonjackson's solution is not working for me. I'm using 1.2.0-rc.2 and bootrstrap-ui 0.6.0 (bootstrap3_bis2)

@guillaume86
Copy link

It will not work unless you keep a cache of the promises and return the same promise for the same parameter.
I commented the promise handling in my angular.js source file, hoping they will provide $parseRaw for the next release...

@rtpm
Copy link

rtpm commented Sep 16, 2013

Is there any plunker (angularjs 1.2.0rc2 & angular-ui bs 0.6) with a working temporary solution ? I can't get this working any way.

@xrg
Copy link

xrg commented Sep 19, 2013

IMHO it is clearly an angular.js issue, I had to modify my angular.js as in xrg/angular.js@34b8650 to let it work again

Doing a workaround with a promise cache would set a bad precedent, where all developers need to write that much code for every promise.

@pkozlowski-opensource
Copy link
Member

Hopefully this is going to be addressed on the AngularJS side via angular/angular.js#4158

@pkozlowski-opensource
Copy link
Member

Yay, it was fixed on the AngularJS side!!! The current AngularJS master works perfectly:
http://plnkr.co/edit/mRShRA?p=preview

Closing, we just need to wait for RC3 now!

@soudmaijer
Copy link

RC3 is out, works fine! http://code.angularjs.org/1.2.0-rc.3/

@john-ring
Copy link

This is still broken with the latest stable release of angular 1.2.1. It only works if you are not trying to display a property of the resulting objects. If your result set isn't just a list of strings it still is broken.

Plunkr based on pkozlowski-opensource's but with two properties in the result set objects:
http://plnkr.co/edit/SyDvessCC2hk23VpFL1m?p=preview

@pkozlowski-opensource
Copy link
Member

@JaggyGT use proper syntax: http://plnkr.co/edit/SyDvessCC2hk23VpFL1m?p=preview
Nothing is broken, you just didn't use valid syntax

@john-ring
Copy link

ah, I see now - state.name for state in states. Thanks @pkozlowski-opensource!

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

No branches or pull requests