我是 Angular 新手,在 ng-repeat
中与 ng-click
作斗争。由于某种原因,它只触发一次,并且以下单击会引发以下错误:
Controller :
(function ( window, angular ) {
'use strict'
var LeadsController = function ( $scope, $http, $cookies, breadcrumbFactory ) {
$scope.leads = []
$scope.activeLead = undefined
$scope.breadcrumb = breadcrumbFactory
$scope.getLeads = function () {
$http({
method: 'GET',
url: '/admin/leads'
})
.success( function getLeadsSuccess ( data ) {
$scope.leads = data.data
$scope.activeLead = $scope.leads[0]
})
.error( function getLeadsError ( err ) {
console.error( err )
})
}
$scope.activateLead = function () {
$scope.activeLead = this.lead
}
$scope.getLeads()
}
angular
.module( 'app' )
.controller( 'LeadsController', [
'$scope',
'$http',
'$cookies',
'breadcrumbFactory',
LeadsController
])
})( window, angular );
HTML:
<ul class="list list--dual-line" id="leads-list">
<li ng-repeat="lead in leads">
<a ng-click="activateLead()">
<p>{{ lead.firstName }} {{ lead.lastName }}</p>
<small>{{ lead.email }}</small>
</a>
</li>
</ul>
最佳答案
在此代码中,您将函数 activateLead 替换为被点击的潜在客户:
$scope.activateLead = function ( lead ) {
debugger
$scope.activateLead = lead
}
不确定这条线应该做什么,但这就是问题所在:
$scope.activateLead = lead
关于javascript - ng-click 在 ng-repeat 中只能工作一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36041091/