我有以下情况:
<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选择是如何正确工作的,我需要将profileDetails.preferredTz
与uiSelectModel.selected
绑定。
我尝试过使用scope : true
,但到目前为止所发生的只是ui-select
使用了一个完全不同的模型,或者在初始化时将profileDetails.preferredTz
设置为未定义的。
发布于 2015-11-10 09:49:42
尝试使用nForm
<ng-form timezone ng-model="myModel">
...uiSelect
</ng-form>
https://stackoverflow.com/questions/33626970
复制相似问题