首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >AngularJS将模型向下传递给ui-select

AngularJS将模型向下传递给ui-select
EN

Stack Overflow用户
提问于 2015-11-10 09:42:26
回答 1查看 45关注 0票数 0

我有以下情况:

  1. 表单有一个名为<timeZone ng-model="formModel.timeZone"的指令
  2. 此指令调用web服务来检索时区。
  3. 然后,该指令将它们放在ui-select中。

表单不关心时区列表,这都包含在指令中。它只关心获取和设置选定的时区。

代码-表格:

代码语言:javascript
运行
复制
<time-zone name="preferredTz" ng-model="profileDetails.preferredTz" ng-required="true"></time-zone>

指令(JS):

代码语言:javascript
运行
复制
.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模板)

代码语言:javascript
运行
复制
<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.preferredTzuiSelectModel.selected绑定。

我尝试过使用scope : true,但到目前为止所发生的只是ui-select使用了一个完全不同的模型,或者在初始化时将profileDetails.preferredTz设置为未定义的。

EN

回答 1

Stack Overflow用户

发布于 2015-11-10 09:49:42

尝试使用nForm

代码语言:javascript
运行
复制
<ng-form timezone ng-model="myModel">

 ...uiSelect

</ng-form>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33626970

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档