Kirk Dev Jr Kirk Dev Jr - 1 year ago 45
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

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

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>


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 Source

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>


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

if the value is not an integer.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download