【问题标题】:access ng-model select control inside ng-include在 ng-include 中访问 ng-model 选择控件
【发布时间】:2015-09-24 15:37:00
【问题描述】:

我创建了一个 angularjs 应用程序。在 Thread.html 页面中,我有组合框来加载策略列表。

<select class="txtBox" data-ng-model="editor.strategy">
            <option value="">--Selected Strategy--</option>
            <option data-ng-repeat="s in strategyList" value="{{ s.Name }}">{{ s.Name }}</option>
        </select>

我在同一页面中使用 ng-include 包含模板。

<div data-ng-include="'/views/Editor.html'"></div>  

在 editor.js 控制器中,我第一次能够访问 $scope.editor.strategy。发布数据后,我试图通过查看 $scope.editor = {"strategy":''} 来清除组合框。如何从 editor.js 控制器重置组合框。我不确定我在哪里做错了。请帮忙。

【问题讨论】:

    标签: angularjs drop-down-menu binding model-binding angular-ngmodel


    【解决方案1】:

    您必须发布更多的 editor.js 代码,这样我们才能看到您是如何填充 strategyList 的。由于您使用的是 ng-repeat(为什么不使用 ng-options?),您必须重置 strategyList,而不是 editor.strategy。

    【讨论】:

    • 是使用ajax调用的json数据。我只想重置组合框以保持“选择策略”被选中,即组合框中的顶部项目。
    • 您可以尝试设置 $scope.editor.strategy = '' 而不是 $scope.editor = {strategy: ''} 吗?如果您发布更多 editor.js 代码,我们可以更快地为您提供帮助。你是在使用简单的 ajax 调用还是 $http 并使用 Promise?
    猜你喜欢
    • 2015-12-22
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 2014-10-13
    • 2023-03-18
    • 2018-08-29
    • 1970-01-01
    • 2016-11-17
    相关资源
    最近更新 更多