Kirk Dev Jr Kirk Dev Jr - 4 months ago 6
AngularJS Question

Filter with specific number of file txt in AngularJS

I have a problem in filter of angularjs. I've try to show the data which condition is ordering=1( it's in field in my file) but my code doesnt working.

Here is my code

<script>
function DanhMucController($scope, $http) {
var url = "data/cate.txt";
$http.get(url).success(function(response) {
$scope.DanhMucList = response;
});
}
</script>


Here is my html file

<div ng-app="" ng-controller="DanhMucController">
<ul class="list-unstyled">
<li ng-repeat="danhmuc in DanhMucList | limitTo:12">
<a href="#">{{danhmuc.career_name }}</a>
</li>

</ul>
</div>


and my data file

[
{
"career_id": "1",
"career_name": "Cate1",
"depended": "0",
"ordering": "1"
},
{
"career_id": "2",
"career_name": "Cate2",
"depended": "0",
"ordering": "1"
},
{
"career_id": "3",
"career_name": "Cate3",
"depended": "0",
"ordering": "2"
}
]


The "limitTo" just get 12 first element. I wanna get to specific number.
it's look like sql: select * from table1 where ordering=1
Thanks for your answer

Answer

After the update, I am able to answer your question. The easiest solution is to have

<li ng-repeat="danhmuc in DanhMucList" ng-if="danhmuc.ordering == 1">
  <a href="#">{{danhmuc.career_name }}</a>
</li>

or

ng-if="danhmuc.ordering == '1'"

if the value is not an integer.

Comments