bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Typehead broken when using promises in Angularjs 1.2.0rc2

Open overloadnn opened this issue 13 years ago • 21 comments

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

overloadnn avatar Sep 05 '13 11:09 overloadnn

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

pkozlowski-opensource avatar Sep 05 '13 12:09 pkozlowski-opensource

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

vpixle avatar Sep 05 '13 12:09 vpixle

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

@overloadnn do you have other reproduce scenario?

pkozlowski-opensource avatar Sep 05 '13 12:09 pkozlowski-opensource

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.

vpixle avatar Sep 05 '13 13:09 vpixle

http://plnkr.co/edit/SXcZXTemPWz3snIUniwb

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

overloadnn avatar Sep 05 '13 13:09 overloadnn

Here's the commit from angular which broke using promise with typeahead: https://github.com/angular/angular.js/commit/3a65822023119b71deab5e298c7ef2de204caa13

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

countableSet avatar Sep 05 '13 19:09 countableSet

@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.

pkozlowski-opensource avatar Sep 06 '13 07:09 pkozlowski-opensource

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.

wilsonjackson avatar Sep 06 '13 20:09 wilsonjackson

@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;
    });

overloadnn avatar Sep 07 '13 12:09 overloadnn

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.

frapontillo avatar Sep 10 '13 10:09 frapontillo

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.

pkozlowski-opensource avatar Sep 10 '13 11:09 pkozlowski-opensource

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

muehle avatar Sep 12 '13 14:09 muehle

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...

guillaume86 avatar Sep 12 '13 14:09 guillaume86

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.

rtpm avatar Sep 16 '13 08:09 rtpm

IMHO it is clearly an angular.js issue, I had to modify my angular.js as in xrg/angular.js@34b8650cdf5a49f37582fce2dacac5e478f75e35 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.

xrg avatar Sep 19 '13 08:09 xrg

Hopefully this is going to be addressed on the AngularJS side via https://github.com/angular/angular.js/issues/4158

pkozlowski-opensource avatar Sep 29 '13 18:09 pkozlowski-opensource

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!

pkozlowski-opensource avatar Oct 11 '13 17:10 pkozlowski-opensource

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

soudmaijer avatar Oct 15 '13 08:10 soudmaijer

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

john-ring avatar Nov 21 '13 16:11 john-ring

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

pkozlowski-opensource avatar Nov 21 '13 16:11 pkozlowski-opensource