点击无效
Ng-click not working
我有一个控制器,我在其中启动一个 http 请求,一旦请求完成,我调用另一个视图然后使用 ng-click
。但是我的 ng-click
不工作。
这是我的代码。
app.controller('listuser', function ($scope,$http,$log,$window) {
$scope.userdetail = {};
return $http({
method: 'POST',
url: 'apisource.php',
})
.then(function (results) {
$scope.data=results.data;
return $scope.data;
});
$scope.douserdetail = function(user) {
alert('test');
};
});
<tr data-ng-repeat="x in data">
<td>
<input type="hidden" name="id" ng-model="userdetail.id" value="{{x.id}}" />
<a href='' ng-click="douserdetail(userdetail)" class="user-link">{{x.First_Name}}{{x.Last_time}}</a>
<span class="user-subhead">{{x.Phd_University}}</span>
</td>
</tr>
您应该只使用 div 或按钮类型的元素,而不是 'a' 标签。
将标签更改为 div 或其他内容,它将起作用
<div ng-click="douserdetail(userdetail)" class="user-link">{{x.First_Name}}{{x.Last_time}}</div>
您的代码在您显示的第 3 行的控制器中有一个 return
,因此没有执行超出 return 语句的代码,试试这个:
app.controller('listuser', function ($scope,$http,$log,$window) {
$scope.userdetail = {};
$scope.data = [];
var init = function () {
$http({
method: 'POST',
url: 'apisource.php',
})
.then(function (results) {
$scope.data=results.data;
});
};
init();
$scope.douserdetail = function(user) {
alert('test');
};
});
我有一个控制器,我在其中启动一个 http 请求,一旦请求完成,我调用另一个视图然后使用 ng-click
。但是我的 ng-click
不工作。
这是我的代码。
app.controller('listuser', function ($scope,$http,$log,$window) {
$scope.userdetail = {};
return $http({
method: 'POST',
url: 'apisource.php',
})
.then(function (results) {
$scope.data=results.data;
return $scope.data;
});
$scope.douserdetail = function(user) {
alert('test');
};
});
<tr data-ng-repeat="x in data">
<td>
<input type="hidden" name="id" ng-model="userdetail.id" value="{{x.id}}" />
<a href='' ng-click="douserdetail(userdetail)" class="user-link">{{x.First_Name}}{{x.Last_time}}</a>
<span class="user-subhead">{{x.Phd_University}}</span>
</td>
</tr>
您应该只使用 div 或按钮类型的元素,而不是 'a' 标签。 将标签更改为 div 或其他内容,它将起作用
<div ng-click="douserdetail(userdetail)" class="user-link">{{x.First_Name}}{{x.Last_time}}</div>
您的代码在您显示的第 3 行的控制器中有一个 return
,因此没有执行超出 return 语句的代码,试试这个:
app.controller('listuser', function ($scope,$http,$log,$window) {
$scope.userdetail = {};
$scope.data = [];
var init = function () {
$http({
method: 'POST',
url: 'apisource.php',
})
.then(function (results) {
$scope.data=results.data;
});
};
init();
$scope.douserdetail = function(user) {
alert('test');
};
});