Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 角度国家/地区选择模块未选择默认值_Angularjs_Jquery Select2 - Fatal编程技术网

Angularjs 角度国家/地区选择模块未选择默认值

Angularjs 角度国家/地区选择模块未选择默认值,angularjs,jquery-select2,Angularjs,Jquery Select2,我正在使用模块。 我无法将默认选定值设置为下拉列表 <input country-select data-ng-model="userCtrl.country" class="signup-country" placeholder="Country*" ng-required="true" name="country" id="signUpCountry" value="{{userCtrl.country}}"> }])) 但这也不会选择默认值。 非常感谢您的帮助。我可以通过添加

我正在使用模块。 我无法将默认选定值设置为下拉列表

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

但这也不会选择默认值。
非常感谢您的帮助。

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

angular.module('angular-country-select', [])
.directive('countrySelect', ['$timeout', function($timeout) {
  return {
  restrict: 'A',
  require:'ngModel',
  link: function(scope, elem, attrs, ngModelCtrl) { console.log(attrs, attrs.placeholder);
    var data = [{"id":"AF","text":"Afghanistan"},{"id":"AX","text":"Åland Islands"},...];
    var select2Inst = elem.select2({
      data: data
    });
    $timeout(function() {
      if (attrs.value != '') {
        ngModelCtrl.$setViewValue(attrs.value);
        scope.$apply(select2Inst.select2('val', attrs.value));
      }
    }, 2000);
  }
};
}]);
angular.module('angular-country-select', [])
.directive('countrySelect', ['$timeout', function($timeout) {
  return {
  restrict: 'A',
  require:'ngModel',
  link: function(scope, elem, attrs, ngModelCtrl) { console.log(attrs, attrs.placeholder);
    var data = [{"id":"AF","text":"Afghanistan"},{"id":"AX","text":"Åland Islands"},...];
    var select2Inst = elem.select2({
      data: data
    });
    $timeout(function() {
      if (attrs.value != '') {
        ngModelCtrl.$setViewValue(attrs.value);
        scope.$apply(select2Inst.select2('val', attrs.value));
      }
    }, 2000);
  }
};
}]);