Rony
Rony

Reputation: 9511

Angularjs binding not working when called from ng-click

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();

        });
    }

Upvotes: 0

Views: 91

Answers (1)

basarat
basarat

Reputation: 276161

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

Upvotes: 3

Related Questions