如何从angularjs中的国家ID获取国家/地区名称

时间:2016-12-06 07:04:58

标签: javascript jquery html angularjs bind

大家好,抱歉,这是一个菜鸟问题 但我遇到了一个问题。问题是: 我从数据库获取国家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。

1 个答案:

答案 0 :(得分:0)

您可以使用ng-model作为

"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="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>

相关问题