我想这样做:
ng-show="node.status | limitTo:1:1 == 1"
在一个简单的角度表达式中,它起作用:{{ node.status | limitTo:1:1 }}
= 1
我无法在ngShow或ngIf语句中使用它....
答案 0 :(得分:1)
limitTo
仅适用于 ng-repeat
,您不能使用 ng-if
或 ng-show
强>
创建仅包含指定数量的新数组或字符串 元素。元素取自开头或结尾 源数组,字符串或数字,由值和指定 限制的标志(正面或负面)。
或者你可以拥有一个实现逻辑的函数,并在 ng-if
或 ng-show
答案 1 :(得分:0)
您可以使用charAt
从字符串中获取指定的字符,然后使用
ngIf
/ ngShow
或ngSwitch
:
var app = angular
.module("myApp", [])
.controller("myCtrl", function ($scope) {
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
<body ng-app="myApp" ng-controller="myCtrl">
<div ng-repeat="node in [{status: '*C,1,0,19,064'}, {status: '*S,1,0,19,064'}] track by node.status">
<div ng-if="node.status.charAt(1) === 'C'">This is status C</div>
<div ng-if="node.status.charAt(1) === 'S'">This is status S</div>
</div>
<hr/>
<div ng-repeat="node in [{status: '*C,1,0,19,064'}, {status: '*S,1,0,19,064'}] track by node.status"
ng-switch="node.status.charAt(1)">
<div ng-switch-when="C">This is status C</div>
<div ng-switch-when="S">This is status S</div>
<div ng-switch-default>This is default status</div>
</div>
</body>