angular.js - Can angular's ng-switch use true as a judgment condition?
漂亮男人
漂亮男人 2017-05-15 17:13:13
0
1
737

How to use ng-switchh to display different contents according to different array lengths. If you use arr.length as the judgment condition, you need to write a lot of situations, so I considered using true as the judgment condition, but I don’t know how to write ng-switch-when , of course it can also be achieved using ng-if, but I have a question about how to write ng-switch, thank you.
The code is as follows:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>title</title>
    <script src="angular.js"></script>
    <style>

    </style>
</head>
<body ng-app="App">
<p ng-controller="Ctrl">
    <p ng-switch="arr.length">
        <span ng-switch-when="1">1</span>
        <span ng-switch-when="2">2</span>
        <span ng-switch-when="3">3</span>
    </p>

    <p>
        <span ng-if="arr.length<2">1---</span>
        <span ng-if="arr.length>=2">2---</span>
    </p>

    <p ng-switch=true>
        <span ng-switch-when="(arr.length==0)"> 1---true </span>
        <span ng-switch-when="(arr.length==0)"> 2---true </span>
    </p>
</p>

<script>
    var App = angular.module("App", []);
    App.controller("Ctrl", ["$scope", function ($scope) {
        $scope.arr = [1, 2,3];
    }]);
</script>
</body>

</html>
漂亮男人
漂亮男人

reply all(1)
大家讲道理
<ul ng-switch="arr">
    <li ng-switch-when="1">1111111</li>
    <li ng-switch-when="2">222222222</li>
    <li ng-switch-when="3">333333333</li>
    <li ng-switch-default=" arr>3">4444444444444444444444444444</li>
</ul>

$scope.arr= arr.length;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template