gpt4 book ai didi

angularjs - Angular - ng-click 不起作用

转载 作者:行者123 更新时间:2023-12-04 22:12:25 25 4
gpt4 key购买 nike

在我看来,我有:

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

ul 部分工作正常,但是当我单击按钮时没有调用 getPerson()?不显示警报。

我的 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');
}
});

难道我做错了什么?

最佳答案

该函数需要在 $scope 上:更改:

function getPerson() {

至:
$scope.getPerson = function() {

关于angularjs - Angular - ng-click 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24957706/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com