I am new to AngularJS, so please help me out.
I have a code that generates dropdownlists onclick of a button.
The dropdownlists fetch the data from database and get populated. I have populated them by using LINQ from the controller.cs file.
The values are bound to each dropdown using
ng-model=item.projectId
Where item is the returned list from the controller.cs and projectId is the ID that we are using to identify the project.
Now I want to send all the selected values of each dropdown list to the server.
I am using 2 ng-model directives over here, one is for getting the data populated in the dropdownlists and the second one is for sending the values to the server, which is in the division that wraps the earlier ng-model code.
Actually what I want to do is, I am generating the dropdowns on click of add projects, and I want to store these selected values of these dropdowns in array and send it to the controller(mvc.net controller server side code) to further save it to the database.
I have provided the code.
Here's a the code...
//the controller for adding more dropdowns on click - "Add more projects"
//custom directive (alert) to add new dropdons
<alert ng-repeat="alert in alerts" type="alert.type" close="closeAlert($index)" >
<ul style="list-style-type: none; margin-left: 0px;" >
<li>
<select data-ng-model="selectedProject[$index]"
data-ng-options="test.ProjectId as test.ProjectName for test in items" id="Project">
<option value="">-- Choose a Project --</option>
</select>
<button type="button" ng-click="closeAlert($index)"><img src="delete.png" alt="Remove" style="height:20px; width:20px;" /></button>
</li>
</ul>
</alert>
<button class='btn' type='button' ng-click="addAlert()">Add Projects</button>
code for app.js this is my create controller
var CreateCtrlEmp = function ($scope, $location, SampleEmp, SampleProj, SampleDes, sharedValues) {
//gets the projects dropdown populated with values
$scope.items = SampleProj.query({ q: $scope.query });
//gets the designation dropdown populated with values
$scope.itemsd = SampleDes.query({ q: $scope.query });
//save function
$scope.save = function () {
SampleEmp.save($scope.item);
$location.path('/emp');
};};
//function that will add new dropdowns on click of "add more projects"
function AlertDemoCtrl($scope) {
$scope.alerts = [
];
$scope.addAlert = function () {
$scope.alerts.push({});
};
$scope.closeAlert = function (index) {
$scope.alerts.splice(index, 1);
};
}
Please help me out. I want to get the list of projects in the array and send that array for further processing. Thanx, Tushar Sharma