大家好,很抱歉这个菜鸟问题 但我遇到了一个问题。问题是: 我正在从数据库获取国家/地区 ID,并且我想显示所选国家/地区名称 这是代码
$scope.Customer.CU_Country = data.cU_Country;
我使用 ng-model 在 html 上获取 Id
ng-model="Customer.CU_Country"
我想根据国家/地区 idin html 显示国家/地区名称,我该怎么做? 这里的字段是
id and name
但是当我使用 html 显示国家/地区时
{{Customer.CU_Country}}
然后它显示国家/地区 ID,我如何替换名称中的 ID。
最佳答案
您可以使用 ng-model 作为
"Customer.CU_Country.name"
演示
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="angular.js@1.4.7" 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>
关于javascript - 如何从angularjs中的国家ID获取国家名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40989646/