I am using AngularJS to show and retreive data from my users in HTML like:
<table id="app2" ng-app="categories" ng-cloak="" class="table table-hover" style="margin-top: 50px;">
<tr style="background-color:#4d748f; color:white;">
<th colspan="5" style="text-align:center; font-size:16px;">Add category</th>
</tr>
<tr>
<form novalidate>
<td colspan="4">
<input type="text" class="form-control" placeholder="Category name"></input>
</td>
<td colspan="1">
<input type="submit" class="btn btn-success"></input>
</td>
</form>
</tr>
<tr style="background-color:#4d748f; color:white;">
<th colspan="5" style="text-align:center; font-size:16px;">Add product</th>
</tr>
<tr>
<form ng-controller="category">
<td colspan="1">
<select class="form-control m-b-10">
<option ng-repeat= "c in categories">{{c[1]}}</option>
</select>
</td>
<td colspan="1">
<select class="form-control m-b-10">
<option>Antwerpen</option>
<option>Leuven</option>
</select>
</td>
<td colspan="1">
<input type="text" class="form-control" placeholder="Name"></input>
</td>
<td colspan="1">
<input type="text" class="form-control" placeholder="Price" width="10%"></input>
</td>
<td colspan="1">
<input type="submit" class="btn btn-success" ng-click="product()"></input>
</td>
</form>
</tr>
</table>
ANGULARJS
categories = angular.module('categories', []);
categories.controller("category",function($scope, $http){
var serviceBase = 'api/';
$http.get(serviceBase + 'categories').then(function (results) {
$scope.categories = results.data;
for(var i = 0; i < $scope.categories.length; i++){
var categories = $scope.categories[i];
}
$scope.product = function($scope, $http){
$http.post(serviceBase + 'productadd/'+$scope.catID+'/'+$scope.catID+'/'+$scope.pname+'/'+$scope.pprice).then(function(results){
alert('ok');
});
}
});
});
When I place my ng-controller on the select item to get the ng-repeat = c in categories. Then this works and I get the categories shown in my dropdown. But when I place it on the form tag it doesn't... I have to place it on my form tag because I want to add a product into my database after the user clicks the button to add products. And ng-click=product() gets called.
How can both of those functions function together?