0

I am trying to pass a property in my $scope to my factory. I could console.log it find, but when I try to pass it to my factory, an error occurs.

controller:

    mainFactory.getHigh($scope.products[0]._id, function (bid) {
        $scope.bid1 = bid;
    });

factory

  factory.getHigh = function (id, callback) {
        $http.post('/high', id)
            .then(function (response) {
                callback(response)
            })
    }

error: $scope.products[0]._id is undefined

user7623748
  • 71
  • 1
  • 5
  • Check `$scope.products` – michelem Mar 29 '17 at 03:51
  • 2
    there isn't enough information here to adequately troubleshoot your issue. You suggest that the property has a value when you use `console.log`, but you aren't showing that here, nor are you showing where this value is being set. This error has nothing to do with the factory; it is indicating that `$scope.products[0]` doesn't have an `_id` property at the time the factory is called. – Claies Mar 29 '17 at 03:57
  • See [Why are Callbacks from Promise `.then` Methods an Anti-Pattern](http://stackoverflow.com/questions/35660881/why-are-callbacks-from-promise-then-methods-an-anti-pattern). – georgeawg Mar 29 '17 at 04:01

0 Answers0