2016-07-27 2 views
-1
ausgewählt
<select class="form-control" 
     id="projects" 
     ng-model="parent_id" 
     ng-options="project.id as project.groupingName for project in projects"> 
</select> 

Es gibt eine project ist, die eine gid hat, dass die parent_id passt, aber es kommt immer noch nicht, wie standardmäßig ausgewählt. Um das zu beweisen, ich habe:ng-Modell ist nicht von einer ng-Optionen werden

<div ng-repeat="project in projects" ng-show="project.gid === parent_id"> 
    {{ project }} 
</div> 
+0

So verwenden Sie 'ng-options' und eine verschachtelte' ng-repeat'? – austinthedeveloper

+0

Entschuldigung - Ich habe das Code-Snippet aktualisiert – Shamoon

+0

Bitte erläutern Sie, was Sie zu tun versuchen. – developer033

Antwort

1

Ich sehe es gibt eine Lücke in Ihrem Code für parent_id und Projekt-ID. Ich habe einen Code für Ihre Anforderung geschrieben. Wenn ich richtig verstanden habe, möchten Sie das Projekt anzeigen, wenn die ID dieses Projekts parent_id entspricht. Ich habe update ng-Optionen für Sie korrekt, wie sie nach "ID" des Projekts verfolgen sollten.

Suchen Sie etwas wie http://codepen.io/aechannaveen/pen/NABbXq?

<html ng-app="myApp"> 

<head> 
    <title> 
     My Angular App 
    </title> 
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" type="text/css"> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"> 
    </script> 
    </link> 
</head> 

<body class="container" ng-controller="InputCtrl"> 

    <select class="form-control" id="projects" ng-model="project" ng-options="project as project.groupingName for project in projects track by project.id"> 
     </select> 
    <div ng-show="project.id === parent_id"> 
    Project Selected :{{ project.groupingName }} 
    </div> 
    </body> 
</html> 

Und

angular.module('myApp', []).controller('InputCtrl', ['$scope',function($scope) { 
$scope.parent_id = 2; 
    $scope.projects = [ 
    { 
     "groupingName": "ABC", 
     "id": 1 
    }, 
    { 
     "groupingName": "CDE", 
     "id": 2 
    } ]; 



}]); 
Verwandte Themen