如何从angularjs中的国家/地区获取国家/地区名称
问题描述:
大家好,大家对于noob问题感到抱歉 但是我遇到了一个问题。问题是: 我从数据库中获取国家ID,我想显示所选择的国名 这里是代码如何从angularjs中的国家/地区获取国家/地区名称
$scope.Customer.CU_Country = data.cU_Country;
我使用NG-模型
ng-model="Customer.CU_Country"
上的HTML越来越标识我想在国家idin html的基础上显示国家名称,我该怎么做? 这里的领域是
id and name
,但是当我使用 {{Customer.CU_Country}}
在HTML显示的国家,那么它显示国家ID如何从名称替换ID。
答
您可以使用使用NG-模型
"Customer.CU_Country.name"
DEMO
var menuApp = angular.module("menuApp", []);
menuApp.controller("menuCtrl", function($scope) {
$scope.Customer = {};
$scope.Customer.CU_Country = {
id: 101,
name: "india"
};
});;
<!DOCTYPE html>
<html>
<head>
<script data-require="[email protected]" data-semver="1.4.7" src="https://code.angularjs.org/1.4.7/angular.js"></script>
</head>
<body ng-app='menuApp'>
<div ng-controller="menuCtrl">
<input type="text" name="input" ng-model="Customer.CU_Country.name">
<input type="text" name="input" ng-model="Customer.CU_Country.id">
</div>
</body>
</html>
从数据库中获得两个编号和名称 - 你的'data.cU_Country'应有一个对象像 - '{Id:1,CountryName:'India'}' – Developer
请让我们看看你的代码为c颂歌片段。可能是我们可以更好地回答你。你可以创建一个包含id和title的国家对象。在你的范围内使用它。然后从中获得ID和标题。但无论如何,你的问题似乎需要更多的解释。 – Elnaz