HTML
<div ng-controller="Part2ctrl">
<form novalidate name="f1" ng-submit="SaveData()">
<input type="text" name="tname" ng-model="tab1.Name" ng-class="Submitted?'ng-dirty':''" required autofocus />
<br/> CountryName <select ng-model="CountryID" ng-options="I.CountryID as I.CountryName for I in CountryList" ng-change="GetStatesd()"></select> StateName
<select ng-model="StateID" ng-options="I.StateID as I.StateName for I in StateList"></select><input type="submit" value="{{SubmitText}}" />
</form>
</div>
的Javascript
angular.module("MyApp").controller("Part2ctrl", function($scope, Revservedata) {
$scope.$watch('f1.$valid', function(dee) {
$scope.isFormValid = dee;
}) $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();
}
}) Revservedata.GetCountry().then(function(d) {
$scope.CountryList = d.data;
}) $scope.GetStatesd = function(CountryID) {
Revservedata.GetStates($scope.CountryID).then(function(d) {
$scope.StateList = d.data;
})
}
}
});
}).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;
})