Anton
Anton

Reputation: 2138

how to access data from scope object

I need to get data from $scope.List2 object:

<div ng-app="App">
  <div id="firstlist" ng-controller="Controller">
    <table id="requesttable" class="RequestTable">
      <tr ng-repeat="item2 in List2">
        <td class="selectedItem">{{item2.Title}}</td>
      </tr>
    </table>
    <button id="Reqbutton" onclick="SendRequest()">Send</button>
  </div>
</div>

The problem is that if I put SendRequest function inside controller then it cannot be called (I get "SendRequest() is not defined" message). And if I put the function outside the controller I cannot access List2. What do I miss?

Upvotes: 0

Views: 882

Answers (1)

David Bohunek
David Bohunek

Reputation: 3201

As @sp00m suggested. You should use ng-click instead of onclick on the button. The html would look like this then:

<button id="Reqbutton" ng-click="sendRequest()">Send</button>

In your controller

app.controller('testController', ['$scope', function {
    $scope.list2 = [];

    $scope.sendRequest = function() {
        var test = $scope.list2;    
        ...
    };

}]);

Upvotes: 1

Related Questions