angularjs를 처음 사용하고 드롭 다운에 대한 지시자로 작동하지만 초기 값을 선택하는 데 문제가 있습니다. 나는이 지시어에 대한 속성으로 선택하는 옵션의 이드를 전달해야한다. 나는 ng-Init에서 사용하는 범위 변수에 속성 값을 설정하려고합니다.angularjs의 지시문을 사용하여 드롭 다운에서 옵션을 선택하십시오.
export class ChoiceGroup
{
constructor()
{
var directive: ng.IDirective = {};
directive.restrict = "E";
directive.replace = true;
directive.template = '<div><select name="cmbCG" ng-model="dataSel" ng-options="c.DisplayName for c in data"></select></div>';
directive.link = function ($scope: any, element: JQuery, attributes: any) {
var injector = angular.element(document).injector();
var key = attributes.key;
var cgCacheService: ChoiceGroupsCacheService;
seCGCacheService = injector.get('seChoiceGroupsCacheService');
var values: Array<ChoiceValue>;
values = seCGCacheService.GetChoiceValues(key);
$scope.data = values;
if (attributes.selectedvalue) {
$scope.selectedvalue = values[attributes.selectedvalue];
}
}
return directive;
}
코드는 타이프에 있습니다
여기 내 지시 코드입니다. 내가 dataSel의 값을 하드 코딩하는 경우
<choicegroupcombo key="RecurrenceFrequency" selectedvalue="3"></choicegroupcombo>
즉 NG-INIT = "dataSel = 3"그때는 잘 작동하지만 범위 변수로 설정하면 다음이 작동하지 않습니다 다음은 HTML입니다. 어떻게 문제를 해결할 수 있습니까?
편집 해결. 그에 따라 코드를 업데이트했습니다.
실제 목표는 여기에 무엇입니까? 귀하의 코드는 일반적인 선택 상자가하는 것 이외의 것을하려고하지 않습니다. – codevinsky