从一个div到另一个div访问ng模型



我想从一个div访问另一个div的ng-model值。

HTML:

<div class="form-group" ng-repeat="key in condition.keys">
    <select class="form-control" ng-show="key.aggregator" ng-model="key.aggregator" ng-options="field.name as field.label for (name, field) in aggregators"></select>
    <select class="form-control" ng-model="key.field" ng-options="s.field as s.field for s in subSchema($parent.condition,$index)" ng-change="onFieldChange($parent.condition,$index)" required>
        <option value="">choose one</option>
    </select>
</div>
<div class="form-group mb-left">{{key.field}}
    <select class="form-control" ng-model="condition.operator" ng-options="field.name as field.label for (name, field) in fields | instanceFilter :key.field :condition" required>
        <option value="">choose operator</option>
    </select>
</div>
</div>

正如您所看到的,在一个div的ng-model中有一个key.field。我想在另一个div上访问这个ng-model值,您可以在其中看到instanceFilter。有可能吗?感谢您及时解决此问题

通常,您可以在相同作用域下的任意多个div中使用相同的ng-model绑定。

您的代码试图实现什么并不明显,但您在ng-repeatdiv中绑定到的"key.field"ng-repeat之外的页面其他部分不在同一范围内。

您应该将ng-model="key.field"分配给一个不同的变量,该变量位于外部范围内,而不是key的一部分,该变量仅对集合中的单个项具有范围。

转到那个控制器,然后分配$rootScope.key.field="**

rootScope在整个应用程序中都可用

**

最新更新