在AngularJS中, 我想使用Javascript中定义的范围变量作为' propertySkipCount'在HTML中。我尝试使用{{propertySkipCount}}并直接作为propertySkipCount,但两者都不起作用。
只有将变量替换为值为1时才有效。
的Javascript
$scope.propertySkipCount = 1;
HTML
<div class="form-group" ng-repeat="property in entity.entityPropertyTypes" ng-if="$index > propertySkipCount">
<div class="form-group" ng-repeat="property in entity.entityPropertyTypes" ng-if="$index > {{propertySkipCount}}">
更新
我希望替换后的代码如下所示。如果我像下面的硬编码一样有效。
<div class="form-group" ng-repeat="property in entity.entityPropertyTypes" ng-if="$index > 1">
Plunker
答案 0 :(得分:1)
第一种方法工作正常,请检查
<div class="form-group" ng-repeat="property in entity.entityPropertyTypes" ng-if="$index > propertySkipCount">
答案 1 :(得分:1)
<div class="form-group" ng-repeat="property in entity.entityPropertyTypes" ng-if="$index > propertySkipCount"> Test {{propertySkipCount}}</div>
以上代码应该有效。
答案 2 :(得分:1)
代码看起来很好。它应该可以使用,问题可能与您当前使用的版本有关。
查看:强>
<div ng-app>
<h2>Todo</h2>
<div ng-controller="TodoCtrl">
<div class="form-group" ng-repeat="property in entityPropertyTypes" ng-if="$index > propertySkipCount">Hello ...! ++ {{$index}}</div>
</div>
</div>
可以与 Angular 1.2.1
一起使用 无法正常工作