Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Typeahead: undefined is not a function after selecting a value #1149

Closed
sylouuu opened this issue Oct 14, 2014 · 5 comments
Closed

Typeahead: undefined is not a function after selecting a value #1149

sylouuu opened this issue Oct 14, 2014 · 5 comments
Labels

Comments

@sylouuu
Copy link

sylouuu commented Oct 14, 2014

Hi,

It works, but a little error happens after selecting a value.

<input type="text" class="form-control" name="company" ng-model="contact.company_id" placeholder="Type a company name" bs-typeahead ng-options="company.id as company.name for company in getCompany($viewValue)" required>
$scope.getCompany = function (q) {
    if (q !== null) {
        return CompanyService.search({ company_name: q }, {}).then(function (request) {
            return request.data.data;
        });
    }
};

I have my values, when I click on any, the input is well filled. But,

TypeError: undefined is not a function
    at controller.$render (angular-strap.js:4316:43)

This line:

element.val(selected ? selected.replace(/<(?:.|\n)*?>/gm, '').trim() : '');

I did console.log(selected); before and:

> Company name
> Company name
> 1
> TypeError: undefined is not a function...

1 is the company id. It could be related to #1122...

Any help appreciated.

@sylouuu
Copy link
Author

sylouuu commented Oct 14, 2014

The problem is that your $render method is called twice. One for the company.name and one for company.id.

Also, I tried without remote data:

$scope.getCompany = function (q) {
    return [
        {
            id: 1,
            name: 'test'
        },
        {
            id: 2,
            name: 'test2'
        },
        {
            id: 3,
            name: 'test3'
        },
        {
            id: 4,
            name: 'test4'
        }
    ];
};

It's OK, no error...

@sylouuu
Copy link
Author

sylouuu commented Oct 15, 2014

Could be related to ocombe/ocLazyLoad#71

@cgarvis
Copy link

cgarvis commented Oct 29, 2014

I have a similar probably, async loading of data objects. Options are displayed correctly, but selecting one throws an error:

TypeError: Cannot assign to read only property 'label' of J
    at angular.module.provider.directive.link.controller.$render (http://127.0.0.1:9000/scripts/angular-strap/angular-strap.js:3901:28)
    at http://127.0.0.1:9000/scripts/angular-strap/angular-strap.js:3889:24
    at deferred.promise.then.wrappedCallback (http://127.0.0.1:9000/bower_components/angular/angular.js:11573:81)
    at http://127.0.0.1:9000/bower_components/angular/angular.js:11659:26
    at Scope.$get.Scope.$eval (http://127.0.0.1:9000/bower_components/angular/angular.js:12702:28)
    at Scope.$get.Scope.$digest (http://127.0.0.1:9000/bower_components/angular/angular.js:12514:31)
    at Scope.$get.Scope.$apply (http://127.0.0.1:9000/bower_components/angular/angular.js:12806:24)
    at HTMLInputElement.listener (http://127.0.0.1:9000/bower_components/angular/angular.js:17057:15)
    at http://127.0.0.1:9000/bower_components/angular/angular.js:2853:10
    at forEach (http://127.0.0.1:9000/bower_components/angular/angular.js:325:18) 

Seems that AngularStrap is execting the selected to be an object with either a label or name attribute.

var selected = angular.isDefined(index) ? typeahead.$scope.$matches[index].label : controller.$viewValue;

if(_.isUndefined(selected.label)){
    selected.label = selected.name
}

In my case it's a string

@vmlf01
Copy link
Collaborator

vmlf01 commented Oct 29, 2014

I don't know where that AngularStrap code you included comes from. Maybe you are using an old version of the library? Please update AngularStrap and check again. If you still have a problem, please open a new issue with a plunker replicating the problem if possible.

@lock
Copy link

lock bot commented Jan 26, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot added the outdated label Jan 26, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jan 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants