我試圖使用ng-if在ng-repeat內部但似乎不能正常工作。無法使用ng-if使用ng-repeat
我在StackOverflow中提到了幾個論壇鏈接,但它並沒有幫助我。
我採用了棱角分明的版本1.3.0
HTML
<!DOCTYPE html>
<html ng-app="myModule">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<script src="/js/lib/angular-1.3.0/angular.js"></script>
<script src="/js/lib/controllers/ifRepeatController.js"></script>
</head>
<body>
<div ng-repeat = "data in comments">
<div ng-if="data.type == 'hootsslllll' ">
//differnt template with hoot data
</div>
<div ng-if="data.type == 'story' ">
//differnt template with story data
</div>
<div ng-if="data.type == 'article' ">
//differnt template with article data
</div>
</div>
</body>
</html>
控制器
var myIfRepeat = angular.module('myIfRepeat',[]);
myIfRepeat.controller('IfRepeatController', function ($scope,$http) {
$scope.comments = [
{"_id":"1",
"post_id":"1",
"user_id":"UserId1",
"type":"hoot"},
{"_id":"2",
"post_id":"2",
"user_id":"UserId2",
"type":"story"},
{"_id":"3",
"post_id":"3",
"user_id":"UserId3",
"type":"article"}
];
});
按照第一個條件,第一個行應該不會被顯示(下面查找屏幕截圖以獲取更多參考信息),但該行正在顯示。
參考鏈接:Using ng-if inside ng-repeat?
現在我加入了控制器的建議股利,但我面臨同樣的問題
下面我給出了參考截圖。請幫助我如何解決這個問題,請讓我知道如果進一步澄清。
上工作模型下方設置截圖使用角1.3版本。如果我們使用的角度1.0.2的NF-如果將無法正常工作(以下提供的截圖)
截屏角版本1.0.2
保重:'ngIf'產生其應有的範圍。https://groups.google.com/forum/#!msg/angular/kPRzdcrIzNw/cNaJdguCNeYJ – Mik378
@ Mik378抱歉,無法清楚地理解 – Arun
您是否嘗試使用'ng-show'而不是'ngIf'? – Mik378