Angular5在由ngModel绑定的<select>选项上获取未定义的值

时间:2018-02-11 09:37:48

标签: angular angular5

我的选择框就是这个。 &lt; select class =&#34; custom-select&#34; [(ngModel)] =&#34;设定[0] .isPrivate&#34;&GT; &lt; option [value] =&#34; Y&#34;&gt;是&lt; / option&gt; &lt; option [value] =&#34; N&#34;&gt; No&lt; / option&gt; &LT; /选择&GT; 设置[0] .isPrivate是ENUM(&#39; Y&#39;,&#39; N&#39;)。 我希望选择框设置为“否”为默认值为“N”,如果值为“是”,则为“是”。 目前,当页面加载时,默认值为空。如果我选择了一个值(是或否)并且控制台通过按钮记录它,我会得到未定义的值。

1 个答案:

答案 0 :(得分:1)

如果[value]是字符串

,则应该用引号括起来<select class="custom-select" [(ngModel)]="settings[0].isPrivate"> <option [value]="'Y">Yes</option> <option [value]="'N'">No</option> </select>

试试这个

$resultset=[
    ['ShownName'=>'A'],
    ['ShownName'=>'B'],
    ['ShownName'=>'C'],
    ['ShownName'=>'D'],
    ['ShownName'=>'E'],
    ['ShownName'=>'F'],
    ['ShownName'=>'G']
];
echo "<table>";

$counter=0;
foreach($resultset as $row){ // you while loop
    if($counter%5==0){
        if($counter){
            echo "</tr>";
        }
        echo "<tr>";  // start new row
    }
    echo "<td>";
        echo "<div class=\"card\">";
            echo "<img src=\"img/img_avatar2.png\" alt=\"Avatar\">";
            echo "<div class=\"container\">";
                echo "<h4><b>{$row['ShownName']}</b></h4>";
                echo "<p style=\"font-family:Roboto;\">Architect & Engineer</p>";
            echo "</div>";
        echo "</div>";
    echo "</td>";
    ++$counter;
}
if($mod=$counter%5){
    $colspan=5-$mod;
    echo "<td",($colspan>1?" colspan=\"$colspan\"":""),"></td>"; // complete the row with appropriately sized cell
}
echo "</tr>";

echo "</table>";