为什么下拉列表在ng-submit ='saveform(emp)'中没有绑定 [英] Why dropdown is not binding when its in ng-submit='saveform(emp)'
问题描述
< form novalidate name =f1ng-submit =SaveData()>
< input type =text name =tnameng-model =tab1.Nameng-class =已提交?'ng-dirty':''需要自动对焦/>
选择你的国家
< select ng-model =CountryIDng-options =I.CountryID as I.CountryName for I in CountryListng-change =GetStatesd()>< ; / select>
< select ng-model =StateIDng-options =I.StateID as I.StateName for I in StateList>< / select>
< input type =submitvalue ={{SubmitText}}/>
< / form>
<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>
< br $>
angular.module(MyApp)
.controller(Part2ctrl,函数($ scope,Revservedata){
$ scope.meassage ='';
$ scope.Submitted = false;
$ scope.SubmitText =保存;
$ scope.isFormValid = false;
$ scope.CountryList = null;
$ scope.CountryID = null;
//检查表格是否有效
$范围。$ watch('f1。$ valid',函数(dee){
$ scope.isFormValid = dee;
})
Revservedata.GetCountry()
.then(function(d){
$ scope.CountryList = d.data;
})
//$scope.GetStatesd = function(){
< br $>
// 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;
})
}
$范围.SaveData = function(data){
if($ scope.SubmitText ==Save){
$ scope.meassage = '';
$ scope.isFormValid = true;
if($ scope.isFormValid){
$ scope.SubmitText =please wait ....;
Revservedata.SaveFormData($ scope.tab1)
.then(functio) n(d){
alert(d);
if(d ==Sucess){
cleardata();
}
})
}
}
}
})
.factory(Revservedata,功能($ http,$ q){
var fac = {};
fac.GetCountry = function(){
返回$ http.get(/ Home / GetCountry );
}
fac.GetStates = function(CountryID){
返回$ http.get(/ Home / GetStates?CountryID = + CountryID)
}
fac.SaveFormData = function(data){
var defe r = $ q.defer();
$ http({
url:/ Home / Create,
方法:POST ,
数据:JSON.stringify(数据),
标题:{'content-type':'application / json'}
})
返回defer.promise;
}
返回fac ;
})
我的尝试:
当我在$ scope.SaveData = functio(数据)中的下拉菜单时
{
--------
}然后下拉没有绑定但是当它从表中出来时它的工作fnn
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
推荐答案
范围,Revservedata){
scope, Revservedata) {
scope.meassage ='';
scope.meassage = '';
scope.Submitted = false;
scope.Submitted = false;
这篇关于为什么下拉列表在ng-submit ='saveform(emp)'中没有绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!