Typehead broken when using promises in Angularjs 1.2.0rc2
On search, I get a "Error: matches is undefined" exception.
@overloadnn http://plnkr.co/, please
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 what you see is duplicate of #813 and is already fixed in master via 7589339330caf1916dff178d03d3f5ee69c9178f.
@overloadnn do you have other reproduce scenario?
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.
http://plnkr.co/edit/SXcZXTemPWz3snIUniwb
Switch between versions of angular in index.html and you'll see.
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 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.
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 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;
});
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.
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.
wilsonjackson's solution is not working for me. I'm using 1.2.0-rc.2 and bootrstrap-ui 0.6.0 (bootstrap3_bis2)
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...
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.
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.
Hopefully this is going to be addressed on the AngularJS side via https://github.com/angular/angular.js/issues/4158
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!
RC3 is out, works fine! http://code.angularjs.org/1.2.0-rc.3/
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
@JaggyGT use proper syntax: http://plnkr.co/edit/SyDvessCC2hk23VpFL1m?p=preview Nothing is broken, you just didn't use valid syntax