美文网首页
7. AngularJS中的指令 ng-switch

7. AngularJS中的指令 ng-switch

作者: 小草莓蹦蹦跳 | 来源:发表于2017-10-09 21:24 被阅读0次
<body ng-app=app ng-controller=wmxController>

<ul>
    <li ng-repeat="item in array" ng-switch="item">
        {{item}}
    </li>
</ul>

<hr>

<ul>
    <!--ng-switch必须和ng-switch-when搭配着使用-->
    <li ng-repeat="item in array" ng-switch="item">
        <!--当item和css相等的时候就可以显示-->
        <span ng-switch-when="jq"> {{item}} </span>
    </li>
</ul>

<script src='angular.js'></script>

<script>

    var app = angular.module('app',[]);

    app.controller('wmxController',['$scope',function ($scope) {
        $scope.array = ['html','css','js','jq'];
    }])

</script>
</body>

相关文章

网友评论

      本文标题:7. AngularJS中的指令 ng-switch

      本文链接:https://www.haomeiwen.com/subject/mffmyxtx.html