获取在角度选项标签

时间:2017-03-08 08:52:18

标签: angularjs

我在控制器中有一个像这样的对象:

$scope.organisations = {
"id" : 1,
"name" : "organisation name"
}

和另一个像这样的对象

$scope.region = {
"id" : 1,
"organisation_id" : 1
}

如果organisation.id等于region.organisation_id。

,我想显示选择的组织名称

在视图中我使用了这个

<select
    ng-options="organisation as organisation.name for organisation in organisations track by organisation.id"
    ng-model="region.organisation"
    name="organisation_name"
    class="form-control">
</select>

现在如何显示在我的区域编辑表单中选择的组织项目?

2 个答案:

答案 0 :(得分:0)

试试这个

<select
    ng-options="organisation as organisation.name for organisation in organisations track by organisation.id"
    ng-model="OrganisationName"
    name="organisation_name"
    class="form-control">
</select>

控制器应该是

$scope.OrganisationName = $scope.region.organisation_id

//或

$scope.OrganisationName.id = $scope.region.organisation_id

答案 1 :(得分:0)

试试这个:

&#13;
&#13;
var app = angular.module("app" , []);
app.controller("appCtrl", appCtrl)

function appCtrl($scope){
$scope.organisations = [{
"id" : 1,
"name" : "organisation name"
},{
"id" : 2,
"name" : "organisation name2"
}]
$scope.region = {
"id" : 1,
"organisation_id" : 1
}
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>

<div ng-app="app" ng-controller="appCtrl">
<select
    ng-options="organisation.id as organisation.name for organisation in organisations"
    ng-model="region.id"
    name="organisation_name"
    class="form-control" ng-selected="{{organisation.Id == region.id}}">
</select>
</div>
&#13;
&#13;
&#13;