【问题标题】:ng-show not having any impactng-show 没有任何影响
【发布时间】:2017-08-17 20:04:48
【问题描述】:

我有这个尝试使用 ng-show 的基本示例。如果从国家下拉框中选择了“GB”,我实际上只想显示页面的一部分。当我从下拉框中选择 GB 时,我已验证 ctrl 在其中收到“GB”。但是,这些元素最初并未隐藏在页面上,并且从选择框中选择内容没有任何影响。如有任何帮助,我将不胜感激。

<ng-form name="directorsForm" cc-pitch-form="5" ng-controller="work.myCtrl as ctrl">
    <div class="row cc-form__group">
        <div class="columns large-3">
            <label>Country</label>
        </div>
        <div class="columns large-3 left">
            <select ng-options="country.code as country.name for country in ctrl.countryList" ng-model="ctrl.selectedCountry" />
        </div>
    </div>

    <div ng-show="ctrl.selectedCountry =='GB'">
        <div class="columns large-3">
            <label>Enter address</label>
        </div>
    </div>
</ng-form>

【问题讨论】:

  • 显示你的控制器
  • 您的 ng-show 看起来不错,错误可能在您的控制器或 ng-options 中
  • 我的控制器中没有任何与此相关的逻辑。
  • @MattBoyle 当然有
  • 看起来 Angular 无法使用不正确的 select 自行关闭。见this working jsfiddle。您必须将&lt;select .. /&gt; 更改为&lt;select ..&gt;&lt;/select&gt;

标签: angularjs ng-show angular1.6


【解决方案1】:

替换这一行

<select ng-options="country.code as country.name for country in ctrl.countryList" ng-model="ctrl.selectedCountry" />

喜欢这个

<select ng-options="country.code as country.name for country in ctrl.countryList" ng-model="ctrl.selectedCountry" ></select>

在选择中的自我关闭不适用于角度我希望它有所帮助!

【讨论】: