【问题标题】:Double radio button selection bug AngularJs双单选按钮选择错误AngularJs
【发布时间】:2016-02-19 04:46:47
【问题描述】:

我有一组单选按钮,当我加载我的应用程序时,默认选择第一个单选,所以如果我转到第二个单选,我可以在 HTML 表中看到不同的信息,然后如果我更改我的值过滤器然后发出请求我希望单选按钮再次刷新并选择默认值,但没有发生,第二个单选按钮被选中。

    <div class="radio" ng-init="topTable='topCategory'">
        <label class="radio-inline"><input type="radio" ng-model="topTable" value="topCategory" ng-change="updateTotals('topCategory')">TY Top 30 Categories</label>
        <label class="radio-inline"><input type="radio" ng-model="topTable" value="topSupplier" ng-change="updateTotals('topSupplier')">TY Top 10 Suppliers</label>
        <label class="radio-inline"><input type="radio" ng-model="topTable" value="topBrand" ng-change="updateTotals('topBrand')">TY Top 10 Brands</label>
    </div>

ng-init 使第一个收音机被选中我也使用了这样的功能

    function topRadios() {
        $scope.topTable = "topCategory";

    }

而我的 ng-init 是 "ng-init="topRadios()";

我不知道我是否需要使用 ng-value 代替 value,或者是否需要向我的控制器添加一些逻辑或什么。

有什么帮助吗?

【问题讨论】:

  • 您是否正在尝试做这样的事情? jsfiddle.net/u9vm0ryx/2
  • @BuddhistBeast 你应该提交它作为答案
  • 谢谢,它有效! @BuddhistBeast 你能把它作为一个答案,这样我就可以把它标记为正确。

标签: javascript angularjs


【解决方案1】:

你可以像这样调用函数:

 <button ng-click="triggerTable()" type="button">Refresh</button>

以及对应的功能:

$scope.triggerTable = function() {
    $scope.topTable = "topCategory";
}

Example

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-15
    • 2012-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-23
    • 1970-01-01
    相关资源
    最近更新 更多