AngularJS,如何在父级中使用来自子级的JSON?

时间:2016-09-20 14:10:31

标签: javascript angularjs json

在选择框中选择某个项目时,我想使用父div中的其他字段。在这种情况下,国家 我的代码:

的index.php

<div class="field" id="{{$index+1}}" ng-repeat="t in getTimes(fieldSelect) track by $index")>
    <select name="drop_down" class="marketSelect">
        <option ng-repeat="item in items">{{item.name}}</option>
    </select>
    {{item.country}}
</div>

angular.js

$http({
    method: 'GET',
        url: 'assets/json/currency.json'
    }).then(function successCallback(response) {
        $scope.items = response.data.currency;
    }, function errorCallback(response) {
        console.log("Oh shit, JSON is not working");
});

1 个答案:

答案 0 :(得分:1)

ng-model指令与ng-options

结合使用
<select ng-options="item as item.name for item in items" 
        ng-model="selectedItem">
</select>

然后在你的div中:

{{ selectedItem.country }}

请参阅this jsfiddle