search

Home  >  Q&A  >  body text

angular.js - ng-show不能正常使用是为什么?

                                        <p class="form-group">
                                            <label class="block">
                                                虚拟用户
                                            </label>
                                            <p class="clip-radio radio-primary">
                                                <input type="radio" id="us-novirtual" name="virtualed" value="false" ng-model="user.virtual" >
                                                <label for="us-novirtual">
                                                    否
                                                </label>
                                                <input type="radio" id="us-virtual" name="virtualed" value="true" ng-model="user.virtual" >
                                                <label for="us-virtual">
                                                    是
                                                </label>
                                            </p>
                                        </p>                            
                        
                                  <p class="form-group" ng-show="user.virtual">
                                            <label class="control-label">
                                                {{user.virtual}}
                                            </label>
                                            <input type="text" placeholder="请输入新密码" class="form-control" name="password" ng-model="user.password" value="">
                                        </p>
                                        
                                        请问当{{user.virtual}}随着上面的输入true false值变换的时候,为什么ng-show不会随着值得变化相应显示或者消失呢?
淡淡烟草味淡淡烟草味2744 days ago546

reply all(1)I'll reply

  • 滿天的星座

    滿天的星座2017-05-15 17:02:55

    The true and false you entered are strings. Angular determines that the string is not empty, so user.virtual = true, so it will not disappear. Did you initialize data for user.virtual in the background?

    reply
    0
  • Cancelreply