0

What am I doing wrong? search() works when called within the controller but not when called through ng-click="search()"

$scope.search = () => {
        $scope.getLocation()
            .then(location => xhr('/venues/search', { lat: location.lat, lng: location.lng, category: $scope.category }))
            .then(data => {
            $scope.venues = data;
            $scope.apply();

        });
    }
3
  • Did you mean to write $scope.$apply(), if so, that might be a problem given the fact that ng-click is handled within a $digest loop. Commented Nov 21, 2014 at 20:31
  • I tried removing the apply() too, still he same result Commented Nov 21, 2014 at 20:44
  • 1
    I found out the problem, the ng-click was not declared inside the controller, thanks @Vadim Commented Nov 21, 2014 at 20:51

1 Answer 1

3

Please do not put stuff directly on $scope. It is considered bad practice, suffers from accidental prototypal member overrides and defeats the purpose of using a class as a Controller.

These are covered in (disclaimer:my) video : https://www.youtube.com/watch?v=WdtVn_8K17E

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.