<form novalidate name="f1" ng-submit="SaveData()">
<input type="text" name="tname" ng-model="tab1.Name" ng-class="Submitted?'ng-dirty':''" required autofocus />
Select Your Country
<select ng-model="CountryID" ng-options="I.CountryID as I.CountryName for I in CountryList" ng-change="GetStatesd()"></select>
<select ng-model="StateID" ng-options="I.StateID as I.StateName for I in StateList"></select>
<input type="submit" value="{{SubmitText}}" />
</form>
angular.module("MyApp")
.controller("Part2ctrl", function ($scope, Revservedata) {
$scope.meassage = '';
$scope.Submitted = false;
$scope.SubmitText = "Save";
$scope.isFormValid = false;
$scope.CountryList = null;
$scope.CountryID = null;
//check Form is Valid or not
$scope.$watch('f1.$valid', function (dee) {
$scope.isFormValid = dee;
})
Revservedata.GetCountry()
.then(function (d) {
$scope.CountryList = d.data;
})
//$scope.GetStatesd = function () {
// Revservedata.GetStates($scope.CountryID)
// .then(function (d) {
// alert("pppp");
// $scope.StateList = d.data;
// })
//}
$scope.GetStatesd = function (CountryID) {
$scope.StateID = null;
$scope.StateList = null;
alert('ddddd');
Revservedata.GetStates($scope.CountryID)
.then(function (d) {
$scope.StateList = d.data;
})
}
$scope.SaveData = function (data) {
if ($scope.SubmitText == "Save") {
$scope.meassage = '';
$scope.isFormValid = true;
if ($scope.isFormValid) {
$scope.SubmitText = "please wait....";
Revservedata.SaveFormData($scope.tab1)
.then(function (d) {
alert(d);
if (d == "Sucess") {
cleardata();
}
})
}
}
}
})
.factory("Revservedata",function($http,$q){
var fac = {};
fac.GetCountry = function () {
return $http.get("/Home/GetCountry");
}
fac.GetStates = function (CountryID) {
return $http.get("/Home/GetStates?CountryID=" + CountryID)
}
fac.SaveFormData = function (data) {
var defer = $q.defer();
$http({
url: "/Home/Create",
method: "POST",
data: JSON.stringify(data),
header: { 'content-type': 'application/json' }
})
return defer.promise;
}
return fac;
})
What I have tried:
when my dropdown within the $scope.SaveData=functio(data)
{
--------
}then dropdown not binding but when its out from the table its working fnn