angularjs - Angular - ng-click 不起作用

标签 angularjs

在我看来,我有:

<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/

相关文章:

javascript - AngularJS 将复选框绑定(bind)到模型属性

javascript - AngularJS 在更改时克隆选择框并将所有选择框值应用到同一模型数组

javascript - 如何使用内置进度条获得工作按钮动画?

javascript - 使用 AngularJS 通过查询数组来创建即时搜索

javascript - AngularJS - $filter 未定义

javascript - 使用 moment js 创建一个包含星期几和一天中几小时的数组?

AngularJS : tomorrow's date and yesterday's date with some ng component

javascript - 如何将 UI Bootstrap Datepicker 从 Controller 更改为指令

javascript - AngularJS & web2py : calling python from ng/javascript/html

node.js - 我应该将 Angular 代码放在这个 Mean.js 应用程序的什么位置才能使这个列表可排序?