[英]AngularJS passing a model down to ui-select
我有以下情况:
<timeZone ng-model="formModel.timeZone"
的指令 该表格并不关心时区列表,这些都包含在指令中。 它只关心获取和设置选定的时区。
代码-形式:
<time-zone name="preferredTz" ng-model="profileDetails.preferredTz" ng-required="true"></time-zone>
代码-指令(JS):
.directive('timeZone', function (staticCommonResourcesAPI) {
return {
restrict: 'E',
require: 'ngModel',
templateUrl: 'shared/partials/timezoneField.tpl.html',
link: function(scope, element, attr, ngModel){
scope.timezones = [];
staticCommonResourcesAPI.getTimezones().then(function (response) {
scope.timezones = response.payload;
});
}
};
});
代码-指令(HTML模板)
<ui-select
id="timezoneCode"
name="timezoneCode"
required="true"
theme="bootstrap"
ng-disabled="disabled || signupStatusTag">
<ui-select-match>{{$select.selected.code}}</ui-select-match>
<ui-select-choices repeat="timezone.code as timezone in timezones | filter: $select.search" class="ui-select-override-top-style">
<span class='no-underline'>{{timezone.name}}</span>
</ui-select-choices>
</ui-select>
如果我了解ui-select如何正常工作,则需要将profileDetails.preferredTz
与uiSelectModel.selected
绑定。
我试过使用scope : true
,但是到目前为止,所有的事情是ui-select
完全使用了不同的模型,或者最终在初始化时将profileDetails.preferredTz
设置为undefined。
尝试使用nForm
<ng-form timezone ng-model="myModel">
...uiSelect
</ng-form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.