4

In my view I have:

<button ng-click="getPerson()">test</button>
<ul>
    <li ng-repeat="person in persons">{{ person.name + ' - ' + person.username }}</li>
</ul>

The ul-part works fine, but getPerson() is not called when I click the button? The alert is not shown.

My controller:

app.controller('personsController', function ($scope, personsService) {
getPersons();
function getPersons() {
    personsService.getPersons()
        .success(function (persons) {
            $scope.persons = persons;
        })
        .error(function (error) {
            $scope.status = 'Error: ' + error.message;
        });
}

function getPerson() {
    alert('tst');
}
}); 

Am I doing something wrong?

1 Answer 1

12

The function needs to be on the $scope: Change:

function getPerson() {

To:

$scope.getPerson = function() {
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.