angular-country-select模块不选择默认值

时间:2015-08-13 06:43:16

标签: angularjs jquery-select2

我正在使用angular-country-select模块。 我无法将默认选择的值设置为下拉列表。

<input country-select data-ng-model="userCtrl.country" class="signup-country" placeholder="Country*" ng-required="true" name="country" id="signUpCountry" value="{{userCtrl.country}}">

我尝试修改模块代码以将val传递给select2(因为此模块使用了select2)。以下是修改后的代码:

angular.module('angular-country-select', [])
.directive('countrySelect', [function() {
return {
  restrict: 'A',
  require:'ngModel',
  link: function(scope, elem, attrs, ngModelCtrl) { console.log("elem");
    var data = ["id":"AX","text":"Åland Islands"},{"id":"AL","text":"Albania"}, ....]; //This array has values
    var defaultValue = attrs.value || '';
      ngModelCtrl.$setViewValue(defaultValue);
    var select2Inst = elem.select2({
      data: data,
      val: defaultValue
    });
  }
};

}]);

但是这也没有选择默认值。 任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:1)

我可以通过添加$ timeout来选择默认值 以下是更新的模块代码:

Task.Supervisor.start_child
相关问题