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?
The function needs to be on the $scope
: Change:
function getPerson() {
To:
$scope.getPerson = function() {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With