【问题标题】:AngularJs Select Generated Through PHPAngularJs 选择通过 PHP 生成
【发布时间】:2018-01-29 14:51:53
【问题描述】:

我为我的 AngularJS 应用程序创建了一个简单的 PHP 函数。我想选择默认选项,它应该是可见的。不幸的是,它没有选择我想要的值。

我的功能如下:

function qtyList($selectName, $selectQty){
    $str = '<select ng-model="qty" ng-change="updateCart('.$selectName.',qty)">';

    for($i=1; $i<=100; $i++){
        if($selectQty == $i)
            $str .= '<option ng-selected="selected">'.$i.'</option>';
        else
            $str .= '<option>'.$i.'</option>';
    }

    $str .= '</select>';

    return $str;
}

请提供任何建议。

【问题讨论】:

  • @Mosh Feu,感谢格式化。
  • 我的荣幸 :) 顺便说一下,请accept 回答,以便对其他人有所帮助。

标签: javascript php html angularjs


【解决方案1】:

确保角度模型(数量)也具有正确的值。

<?php


function qtyList($selectName, $selectQty)
{

    $str = '<select ng-init="qty =\'' . $selectQty . '\'" ng-model="qty">';

    for ($i = 1; $i <= 100; $i++) {
        $str .= '<option value="' . $i . '">' . $i . '</option>';
    }

    $str .= '</select>';

    return $str;
}


echo qtyList('testName', "5");

【讨论】:

  • 太好了,正是我需要的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-18
  • 1970-01-01
  • 2017-01-19
  • 1970-01-01
  • 2011-09-08
相关资源
最近更新 更多