2017-12-28 10 views
0

격리 된 범위가있는 지시문을 만들었습니다. 어떤 이유로 ng-repeat에서 범위를 벗어난 범위 ​​값에 액세스 할 수 없습니다 반복. 그래서 여기, ng-options 지시문에서 격리 된 범위 속성 authorityList에 액세스하려고하지만 드롭 다운에 채워지지 않습니다.angularjs ng-options 내 드롭 다운을 채우지 않음

(function() { 

var app = angular.module('garageManagement'); 

app.directive('userManagement', function() { 
    return { 
     restrict: 'E', 
     templateUrl: 'app/directives/userManagementWidget/userManagementTemplate.html', 
     scope: { 
      users: "=", 
      authorityList: "=", 
      acceptUser: "&", 
      rejectUser: "&", 
      selectecAuthroity:"=", 
     } 
    }; 
}); 

}()); 

템플릿

<div class="form"> 
<div class="col-12" ng-repeat="user in users "> 
    <div id="{{user.Id}}" class="row"> 
     <label for="example-text-input" class="col-3 col-form-label">{{user.UserName}}</label> 
     <div class="col-3"> 
    // issue here, authorityList returning undefined 
      <select class="form-control" ng-options="item in authorityList" ng-change="storeSelectionUserType(user.Id)" ng-model="user.StaffType"></select> 
     </div> 
     <div ng-hide="user.IsApproved" class="col-3"> 
      <button type="button" ng-click="acceptUser(user.Id)" class="btn btn-primary col-3">Accept</button> 
     </div> 
     <div ng-hide="user.IsApproved" class="col-3"> 
      <button type="button" ng-click="rejectUser(user.Id)" class="btn btn-primary col-3">Reject</button> 
     </div> 
    </div> 
</div> 

사용

<user-management users="users" authorityList="authorityList" acceptUser="acceptUser" rejectUser="rejectUser" storeSelectionUserType="storeSelectionUserType" selectecAuthroity="selectecAuthroity"></user-management> 
+1

문제를 재현하는 플 런커 데모 만들기 – charlietfl

답변

0

예를 들어 아래를 참조하십시오.

<select name="repeatSelect" id="repeatSelect" ng-model="data.model"> 
     <option ng-repeat="option in data.availableOptions" value="{{option.id}}">{{option.name}}</option> 
</select> 

angular.module('ngrepeatSelect', []) 
.controller('ExampleController', ['$scope', function($scope) { 
    $scope.data = { 
    model: null, 
    availableOptions: [ 
     {id: '1', name: 'Option A'}, 
     {id: '2', name: 'Option B'}, 
     {id: '3', name: 'Option C'} 
    ] 
    }; 
}]); 
0

키와 값을 ng-options에 할당해야합니다. 이것을 이렇게 바꿔주세요.

<select class="form-control" ng-options="item.id as item.name for item in authorityList" ng-change="storeSelectionUserType(user.Id)" ng-model="user.StaffType"></select>