First picture.
Code
<! DOCTYPE html>
<meta charset= "Utf-8" >
<meta http-equiv= "x-ua-compatible" content= "Ie=edge" >
<meta name= "viewport" content= "Width=device-width, initial-scale=1" >
<script src= "JQuery.min.js" ></script>
<script src= "Angular.js" ></script>
<script src= "Bootstrap.min.js" ></script>
<link rel= "stylesheet" href= "Bootstrap.min.css" >
<style type= "Text/css" >
Select {
width:116px;
}
. selectlocation Select {
Display:block;
Float:left;
margin-bottom:2px;
}
</style>
<script type= "Text/javascript" >
var myApp = angular.module (' myApp ', []);
Myapp.controller (' Ctrl ', [' $scope ', ' Utilsservice ', function ($scope, utilsservice) {
$scope. location = ';
$scope. $watch (' Location ', function (newvalue) {
Console.log (NewValue)
Console.log (Utilsservice.isemptyobj (NewValue))
})
if (Isemptyobj ($scope. Location)) {
Error
// }
}]);
Myapp.factory ("Utilsservice", function () {
return {
Isemptyobj:function (obj) {
var flag = true;
for (var i in obj) {
if (Obj[i]!= ') {
Flag = false;
Break
}
}
return flag;
}
}
})
Myapp.directive ("Custlocation", [' $http ', function ($http) {
return {
Restrict: ' A ',
Scope: {
Ngmodel: ' = '
},
Templateurl: ' tmpl.html ',
Link:function (Scope, Elem, attrs) {
Scope.country = ';
Scope.province = ';
scope.city = ';
scope.detailaddress = ';
$http. Get ("Location.json"). Success (function (data) {
Scope.countrylist = Data.country;
});
Scope. $watch (' detailaddress ', function (newvalue) {
Console.log (scope.country.name + scope.province.name + scope.city + newvalue)
Scope.ngmodel = {
"Country": Scope.country = = NULL | | Scope.country = = "? ": Scope.country.name,
"Province": scope.province = = NULL | | Scope.province = = "? ": Scope.province.name,
"City": scope.city | | '',
"Detailaddress": newvalue
};
});
Scope.changecountry = function () {
if (scope.country = = null) {
Scope.country = ';
Scope.province = ';
scope.city = ';
scope.detailaddress = ';
Scope.ngmodel = ';
} else {
Scope.ngmodel = {
"Country": Scope.country.name,
"Province": scope.province = = NULL | | Scope.province = = "? ": Scope.province.name,
"City": scope.city | | '',
"Detailaddress": scope.detailaddress
};
}
}
Scope.changeprovince = function () {
Scope.ngmodel = {
"Country": Scope.country.name,
"Province": scope.province = = NULL | | Scope.province = = "? ": Scope.province.name,
"City": scope.city | | '',
"Detailaddress": scope.detailaddress
};
}
scope.changecity = function () {
Scope.ngmodel = {
"Country": Scope.country.name,
"Province": scope.province = = NULL | | Scope.province = = "? ": Scope.province.name,
"City": scope.city | | '',
"Detailaddress": scope.detailaddress
};
}
}
};
}]);
</script>
<body ng-controller= "Ctrl" >
<div cust-location ng-model= "Location" ></div>
</body>
Tmpl.html
<div class= "Selectlocation" >
<div>
<select class= "btn btn-info btn-sm" ng-change= "Changecountry ()" ng-model= "Country" ng-options= "C.name for C in Countrylist ">
<option value= "" > National </option>
</select>
</div>
<div>
<select class= "btn btn-info btn-sm" ng-change= "Changeprovince ()" ng-model= "province" ng-options= "P.name for P in Country.province ">
<option value= "" > Province/Direct 轄 City </option>
</select>
</div>
<div>
<select class= "btn btn-info btn-sm" ng-change= "changecity" ng-model= "City" ng-options= "C for C in Province.city" >
<option value= "" > City </option>
</select>
</div>
<div style= "WIDTH:348PX;" >
<input type= "text" class= "Form-control" ng-model= "detailaddress" placeholder= "Detailed Address" ng-disabled= "country==" ' | | Country==null "/>
</div>
</div>