即使不满足div条件,它也会执行div中的代码。
<div ng-if = "1==11">
nishant
<td><a href="indexForm.jsp?id={{x.id}}" class="btn btn-primary">View Details</a></td>
</div>
在代码中,ng-if不满足,所以不需要通过div,但它不是打印“nishant”而是执行.Kindly,帮助我执行它的原因。
答案 0 :(得分:0)
条件应为
<div ng-if = "1!==11">
<强>样本强>
var app = angular.module('testApp',[]);
app.controller('testCtrl',function($scope){
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="testApp" ng-controller="testCtrl">
<div ng-if = "1==11">
nishant
<td><a href="indexForm.jsp?id={{x.id}}" class="btn btn-primary">View Details</a></td>
</div>
</body>
&#13;
答案 1 :(得分:0)
var app = angular.module('myApp',[]);
app.controller('testCtrl',function($scope){
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="testCtrl">
<div ng-if = "1==11">
nishant False Condition
<td><a href="indexForm.jsp?id={{x.id}}" class="btn btn-primary">View Details</a></td>
</div>
<div ng-app="myApp" ng-controller="testCtrl">
<div ng-if = "1!==11">
nishant true condition
<td><a href="indexForm.jsp?id={{x.id}}" class="btn btn-primary">View Details</a></td>
</div>
</div>
问题在于您的控制器我认为您可以看到此代码没有问题。请检查您的控制台是否有错误
答案 2 :(得分:0)
代码也适用于我。
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
</head>
<body ng-app="app" ng-controller="ctrl">
<div ng-if="1==11">
nishant
<td>
<a href="indexForm.jsp?id={{x.id}}" class="btn btn-primary">View Details</a>
</td>
</div>
<script src="../lib/angular.js"></script>
<script>
var app = angular.module('app', []);
app.controller('ctrl', function ($scope) {
$scope.x = {
id: 1,
name: 'A'
};
})
</script>
</body>
</html>
你说虽然条件没有得到满足,但它正在执行div块?你能解释一下执行是什么意思吗?
这里条件没有得到满足,因此将从DOM中完全删除div标签。您可以在此link上阅读有关ngIf的更多信息。