0

我对 AngularJs 有点陌生,并在一些基本概念上寻求帮助。基本上,以下代码正确显示了从请求 API 返回的数据。

请求.cshtml

<div data-ng-controller="PostsController">
    <strong class="error">{{ error }}</strong>
    <strong data-ng-show="loading">loading..</strong>

    <div data-ng-repeat="request in posts | orderBy: 'Id':true">

        <strong>ID: {{ request.Id }}</strong>
        <strong>Contact No: {{ request.ContactNumber }}</strong>
    </div>

</div>

现在我正在进一步寻找在视图中添加按钮,当用户点击时,应该显示联系号码。我已经编写了以下 html/angular 视图代码。显示号码

我需要帮助在 PostsController.js 文件中编写相应的“ShowNumber()”函数。但我很困惑如何发送单个值而不是列表。请问有什么帮助吗?

这是我当前的 PostsController.js 代码

function PostsController($scope, $http) {

    $scope.loading = true;
    $scope.editMode = false;

    $http.get('/api/request').success(function (data) {
        $scope.posts = data;
        $scope.loading = false;
    })
    .error(function () {
        $scope.error = "An Error has occured while loading posts!";
        $scope.loading = false;
    });



}
4

1 回答 1

1

功能:

$scope.ShowNumber=function(value){  
  //Your logic
}

HTML

<input type="button" value="Show" ng-click="ShowNumber(request.Id)" />

您可以在函数中发送任何值。您还可以发送列表索引:

ng-click="ShowNumber($index)"
于 2013-11-03T20:20:30.993 回答