This is my structure in scope:
$scope.tables = [
{name: 'tweets',
columns: ['message', 'user'],
items: [
{message: 'hello', user: 'mike'},
{message: 'hi', user: 'bob'},
{message: 'hola', user: 'bob'}
]
},
{name: 'users',
columns: ['username'],
items: [
{username: 'mike'},
{username: 'bob'}
]
}
];
This is the "addTweet" function. Since the button that calls this function is generated from a loop, it needs to pass the $index to the function. I've tried the following but it doesn't work. The button doesn't seem to trigger anything at all. If I call the function from outside the loop though, it works.
$scope.addTweet = function(id){
$scope.tables[id].items.push({message: $scope.message, user: $scope.user});
};
<table ng-repeat="table in tables">
<form ng-submit="addTweet($index)">
<tr>
<td ng-repeat="column in table.columns">
<input type="text" ng-model="column"></input>
</td>
<td>
<button type="submit">Add Row</button>
</td>
</tr>
</form>
</table>