NG-如果不使用NG重复和广播按钮

发布于 2025-02-12 12:01:08 字数 1219 浏览 0 评论 0原文

我有以下html模板:

    <div ng-app ng-controller="Ctrl">
    <div class="cont">
        <table>
        <tr><th ng-repeat="column in columns">{{column}}</th></tr>
        
        <tr ng-repeat="(i, row) in people">
          <td ng-repeat="(j, column) in columns">
            <input type="radio" name="select" ng-if="column === 'id'">
            <span>{{row[column]}}</span>
          </td>
        </tr>
        </table>                        
    </div>    
</div>

然后我将ctrl定义为

function Ctrl($scope) {

    $scope.selectedId = 'aaaaa';
    
    $scope.columns = ['id','name', 'age'];
    
    $scope.people=[
        { 
            'id':'aaaaa', 'name':'rachit', 'age':11
        },
        { 
            'id':'bbbbb', 'name':'gulati', 'age':12
        },
        { 
            'id':'ccccc', 'name':'rocks', 'age': 13
        }
    ]
}

https://jsfiddle.net/en91zuxb/een91zuxb/

它显示了所有项目的无线电输入,而我的目的是仅在第一列上显示无线电按钮,因为第一列是id列... ...

I have the following html template:

    <div ng-app ng-controller="Ctrl">
    <div class="cont">
        <table>
        <tr><th ng-repeat="column in columns">{{column}}</th></tr>
        
        <tr ng-repeat="(i, row) in people">
          <td ng-repeat="(j, column) in columns">
            <input type="radio" name="select" ng-if="column === 'id'">
            <span>{{row[column]}}</span>
          </td>
        </tr>
        </table>                        
    </div>    
</div>

Then I define my Ctrl as follow

function Ctrl($scope) {

    $scope.selectedId = 'aaaaa';
    
    $scope.columns = ['id','name', 'age'];
    
    $scope.people=[
        { 
            'id':'aaaaa', 'name':'rachit', 'age':11
        },
        { 
            'id':'bbbbb', 'name':'gulati', 'age':12
        },
        { 
            'id':'ccccc', 'name':'rocks', 'age': 13
        }
    ]
}

https://jsfiddle.net/en91zuxb/

it's showing radio input for all the item, while my intention is to only show the radio button on the first column, because the 1st column is the id column... ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇俏 2025-02-19 12:01:08

看来您的Angular版本是旧的,这是与Angularjs&lt相关的错误; 1.2。尝试升级AngularJS版本或使用NG-Show。

以下代码对我有用。

<input type="radio" name="select" ng-show="column == 'id' ">

It seems that your angular version is old, this was an error related to angularjs < 1.2. Try upgrading your angularjs version or use ng-show instead.

Following code worked for me.

<input type="radio" name="select" ng-show="column == 'id' ">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文