0

I have a scope model called person that has a firstname, lastname and fullname. My goQuery works with this:

$scope.person = $goQuery('person', { userName: $scope.person.findme }, { sort: { 'userName': 'asc' }, limit: 1 }).$sync();

The only problem I'm having is that it only populates the value for the field I'm searching and not the whole model. What am I missing?

Rudy Hinojosa
  • 1,448
  • 14
  • 15

2 Answers2

1

$scope.person.findme throws an error because $scope.person is not yet defined. I'm not sure how this is working at all.

Here's a working example:

$scope.person = $goQuery('person', 'person', { userName: 'user1' }, { sort: { 'userName': 'asc' }, limit: 1 }).$sync();

$scope.person.$add({ userName: 'user1', fname: 'a', lname: 'b'});
$scope.person.$add({ userName: 'user2', fname: 'c', lname: 'd'});
$scope.person.$add({ userName: 'user3', fname: 'e', lname: 'f'});
window.person = $scope.person;

If you look at the model on window.person you should see user1's ID and their data under it.

c m a c
  • 31
  • 3
  • the model is already defined at the init of the controller, which is not displayed. $goQuery is supposed to return the full model back to $scope.person, but instead, I'm only getting the userName field returned. – Rudy Hinojosa May 05 '14 at 18:17
  • $scope.person = $goQuery(...) will overwrite the model you have defined in init, so I would recommend not doing it that way. Either have a separate model to handle the findme input or extend the model after $scope.person = $goQuery(...). – c m a c May 05 '14 at 18:56
  • I was under the impression that is the desired effect. I followed the demo video instructions from https://www.youtube.com/watch?v=RTuovru9miU – Rudy Hinojosa May 06 '14 at 14:17
0

Ok. Thank you Colin MacDonald. This is how you return results into your scope: HTML CODE:

 <label>Find User:</label>
    <input type="text" ng-model="person.findme" placeholder="Enter Full Name to Search..." />
    <input type="button" id="Find" value="Search" ng-click="Find()" />

JAVA SCRIPT:

 $scope.Find = function () {
  console.log('entering find method...')
  $scope.person = $goQuery('person', { userName: $scope.person.findme }, { limit: 1 }).$sync();
       $scope.person.$on('ready', function () {
            var id = $scope.person.$$index[0];
                if (!id) {
                   // no results found
                   return;
                }
       $scope.person = $scope.person[id];
                       $scope.person.id = id;
       });
       };
Rudy Hinojosa
  • 1,448
  • 14
  • 15