Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

ok this is the last question from todays trilogy of learning Angular:

part1

part2

I am getting to following error(when trying to select user in view:

TypeError: object is not a function
    at Object.source (http://localhost:3000/assets/angular.js?body=1:6300:13)
    at getMatchesAsync (http://localhost:3000/assets/angular-ui-bootstrap.js?body=1:1820:30)
    at http://localhost:3000/assets/angular-ui-bootstrap.js?body=1:1871:13
    at http://localhost:3000/assets/angular.js?body=1:12030:15
    at Array.forEach (native)
    at forEach (http://localhost:3000/assets/angular.js?body=1:134:11)
    at $setViewValue (http://localhost:3000/assets/angular.js?body=1:12029:5)
    at http://localhost:3000/assets/angular.js?body=1:11423:14
    at Object.Scope.$eval (http://localhost:3000/assets/angular.js?body=1:7994:28)
    at Object.Scope.$apply (http://localhost:3000/assets/angular.js?body=1:8074:23) angular.js?body=1:5688
(anonymous function) angular.js?body=1:5688
(anonymous function) angular.js?body=1:4785
Scope.$apply angular.js?body=1:8076
listener angular.js?body=1:11422
jQuery.event.dispatch jquery.js?body=1:5096
elemData.handle

with this code (updated according to the SO answers:

  <div ng-app='users'>

    <div class='container-fluid' ng-controller="UsersIndexCtrl">
      <pre>Model: {{result | json}}</pre>
      <input type="text" ng-model="result" typeahead="suggestion for suggestion in users($viewValue)">
    </div>


<script>


    var app = angular.module('users', ['ui.bootstrap', 'ngResource']);

    app.factory('User', function($resource) {
        return $resource("users/:id", { id: '@id' }, {
            index:   { method: 'GET', isArray: true, responseType: 'json' },
            show:    { method: 'GET', responseType: 'json' },
            update:  { method: 'PUT', responseType: 'json' }
        });
    })


    var UsersIndexCtrl = function($scope, User) {
        $scope.users = User.index();
    };


</script>

I am trying to fetch all users from the server using typeahead.

Latest version of plunker code is here

Questions: 1. How to fetch collection data from server and make typeahead running using angular and modifying this code ?. 2. What does this error means and how it is causes in connection to this code.

share|improve this question
    
$scope.users is an array and you are calling it as a function. –  Stewie Aug 19 '13 at 15:32
add comment

1 Answer 1

up vote 2 down vote accepted

Your problem is not with your index function, but in your typeahead directive usage. This is what you want (assuming you want to search by the name property on your User resource:

<div ng-app='users'>
  <div class='container-fluid' ng-controller="UsersIndexCtrl">
    <pre>Model: {{result | json}}</pre>
    <input type="text" ng-model="result" typeahead="user.name for user in users | filter:$viewValue">
  </div>
</div>

I've edited your plunker here so that your example works :)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.