2017-04-13 201 views
0

AngularJS NG選項從NG選擇和嘗試設置默認選擇值

 
app.factory("ParentsFactory", function ($http) {

return $http.get("/home/parents"); 
}) 

ParentsFactory.then(function (data) { 
    $scope.Parents = data.data; 
}); 

<select class="form-control" ng-model="modelparent"> <option value="{{parent.ParentID}}" ng-selected="{{parent.ParentID==2}}" ng-repeat="parent in Parents">{{parent.DocumentNo}} - {{parent.FullName}}</option> </select>

+3

很抱歉,但你有什麼具體問題? –

回答

0

刪除插值括號{{}}:

<select class="form-control" ng-model="modelparent"> 
          <option value="{{parent.ParentID}}" ng-repeat="parent in Parents" ng-selected="parent.ParentID==2">{{parent.DocumentNo}} - {{parent.FullName}}</option> 
         </select> 

編輯:

根據你的數據我編輯了我的答案:

var app=angular.module("app",[]); 
 
app.controller('Ctrl',['$scope',Ctrl]); 
 
    
 
function Ctrl($scope){ 
 
$scope.modelparent = "1"; 
 
    $scope.Parents = [{ "ParentID": 1, "FullName": "Jack", "BirthDate": "/Date(631137600000)/", "BirthPalace": 1, "DocumentType": 1, "DocumentNo": "P544123", "AddDate": "/Date(1483300800000)/", "UpdateDate": null, "LastLoginDate": null }, 
 
    { "ParentID": 2, "FullName": "Ammanda", "BirthDate": "/Date(631137600000)/", "BirthPalace": 1, "DocumentType": 1, "DocumentNo": "P5441234", "AddDate": "/Date(1483300800000)/", "UpdateDate": null, "LastLoginDate": null }] 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script> 
 
<div ng-controller="Ctrl" ng-app="app"> 
 
{{Abc}} 
 
<select class="form-control" ng-model="modelparent"> 
 
           <option value="{{parent.ParentID}}" ng-repeat="parent in Parents">{{parent.DocumentNo}} {{parent.FullName}}</option> 
 
          </select> 
 
</div>

+0

珍妮不工作 – jvdnet

+0

@ user3186875請給家長提供數據 – Jenny

+0

數據在哪裏? – jvdnet