【问题标题】:ng-options not binding inside modal dialogng-options 未绑定在模态对话框中
【发布时间】:2015-09-20 22:26:51
【问题描述】:

我有一个模式对话框(ui 引导对话框),它显示一些表单字段以供选择。当我选择并单击保存时,绑定正常,我可以从我的浏览器开发工具栏中看到这一点。但是当我再次打开模式以编辑更改时,下拉列表上的绑定丢失,它们都重置为选择列表中的第一个选项,如果我从开发工具中查看我的模型,则正确的值在那里但没有反映对话框显示。

我有一个处理参数显示的指令“显示参数”

(function(){

function displayParameters(){

    return{
        scope:true,
        restrict:'E',
        templateUrl:'app/templates/displayParameters.html',
        controller:function($scope,globalContainer){
            $scope.globals=globalContainer.variables;



        }

    }
}

angular.module("App").directive("displayParameters",displayParameters);

})();

模板是

<div>
<div class="col-md-4">
    <label class="control-label">{{mapping.CommandMappings[0].Field}}</label>
</div>
<div class="col-md-3">
    <select class="form-control hack" ng-model="mapping.CommandMappings[0].SourceType">
        <option value="1">Event</option>
        <option value="2">Variable</option>
    </select>
</div>
<div class="col-md-5">
    <select ng-options="field for field in foundFields.entityOptions" class="form-control" ng-if="mapping.CommandMappings[0].SourceType==1" ng-model="mapping.CommandMappings[0].ValueSource">
    </select>

    <select class="form-control" ng-if="mapping.CommandMappings[0].SourceType==2" ng-model="mapping.CommandMappings[0].ValueSource"
            ng-options="variable.value as variable['name'] for variable in globals">
    </select>
</div>

我就是这样用的

   <tabset>
       <tab heading="Command Mapping">
           <div style="margin-top:5px">
               <div class="form-group" ng-repeat="mapping in commandMappings">
                   <display-parameters></display-parameters>
               </div>
           </div>
       </tab>
       <tab heading="Variable Mapping">

       </tab>
   </tabset>

附加的还有初始选择和保存以及稍后打开以编辑选定选项之前的对话框图像。还有我绑定的数据结构的图像。 First Time Dialog opens, i make selections and later clicks save

Opens the dialog again but the bindings are gone, all reset to index 0

Inspects the object from console and find the binding is intact

我不知道为什么我在对话框第二次打开时松开了视图上的绑定,但在模型上是正确的

【问题讨论】:

  • 你怎么能说检查对象的绑定是完整的呢?在您的指令中,您仅绑定到SourceTypeValueSource,并且该控制台检查中的相应值是1''

标签: angularjs angular-ui-bootstrap


【解决方案1】:

数据保存到 mapping.CommandMappings[0].ValueSource 中,然后关闭具有控制器的模态对话框,

当你再次尝试打开它时,模态对话框相关的控制器会被初始化
& 也(mapping.CommandMappings[0].ValueSource ={})被初始化。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-10-19
  • 2015-01-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多