简体   繁体   English

为什么下拉列表没有为ng-model的未定义值设置默认值?

[英]Why dropdown is not setting default value for undefined value of ng-model?

I want to set the default value for the dropdown to be set to 1 (now it's not defined. I tried the below code, But it's not working. 我想将下拉菜单的默认值设置为1(现在尚未定义。我尝试了下面的代码,但是不起作用。

I tried to print the value of item.n_fold , it shows blank in the page. 我试图打印item.n_fold的值,它在页面中显示为空白。 I want to set it to 1 for empty, null or undefined value. 我想将其设置为1以表示空,空或未定义的值。

<div flex=5> <md-input-container>
{{item.n_fold}}
<input type="number" step="1" min="1" onkeypress="return (event.charCode == 8 || event.charCode == 0) ? '': event.charCode >= 48 && event.charCode <= 57" id="train_n_file" ng-init="item.n_fold = item.n_fold || '1'" ng-model="item.n_fold" ng-disabled="item.train_select=='training_time_range'" style="margin-top: -2px;" class="input-div" value="{{1}}"> </md-input-container>
</div>

You have a mistake you have written: 您写了一个错误:

g-init= instead of ng-init= g-init =代替ng-init =

so your code for initiation of the dropdown should be as follows 因此,用于启动下拉菜单的代码应如下所示

<div flex=5> <md-input-container>
    {{item.n_fold}}
    <input type="number" step="1" min="1" 
        onkeypress="return (event.charCode == 8 || event.charCode == 0) ? '': event.charCode >= 48 && event.charCode <= 57" 
    id="train_n_file" 
    ng-init="item.n_fold= (item.n_fold || '1')" 
    ng-model="item.n_fold" 
    ng-disabled="item.train_select=='training_time_range'" 
    style="margin-top: -2px;" class="input-div" value="{{1}}"> 
    </md-input-container>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM