Is $scope.list actually an array?
On Jan 30, 2015 3:59 PM, "Kristijan Pokas" <[email protected]>
wrote:
> I've seen your solution.. it is a simple example. :)
>
> My list is following defined:
> $scope.list = $scope[$scope.resourceType + 's'] = Resource.query();
> ....
> $scope.totalItems = 12; //$scope.list;
> $scope.currentPage = 1;
> $scope.itemsPerPage = 5;
>
> ...
>
> .filter('offset', function() {
> return function(input, offset) {
> return (input instanceof Array) ? input.slice(+offset) : input;
> };
> })
>
> the html code is as such as yours.
>
> But I can't $scope.list.length assign to the variable $scope.totalItems..
> only $scope.list
>
> Am Freitag, 30. Januar 2015 19:03:51 UTC+1 schrieb Nicholas Smith:
>>
>> Forgot to link the updated example, it is at
>> http://plnkr.co/edit/vgNJOb2ZfgEmjqHBp1G3?p=preview
>>
>>
>>
>> On Friday, January 30, 2015 at 12:03:18 PM UTC-6, Nicholas Smith wrote:
>>>
>>> I updated my example to directly set $scope.totalItems = list.length and
>>> it is still working fine. There might be another problem in your code can
>>> you resend the javascript and HTML as it looks now?
>>>
>>> To answer your question though, if you need to convert a string to a
>>> number you can use the parseInt function, such as
>>> var a = parseInt("10")
>>>
>>> From your function where you are receiving the data from the server you
>>> could assign $scope.totalItems = results.length from there.
>>>
>>>
>>>
>>> On Friday, January 30, 2015 at 11:37:59 AM UTC-6, Kristijan Pokas wrote:
>>>>
>>>> Nicholas.. have you an idea how could I convert a string in an INT?
>>>>
>>>> That is the only one problem in my code. Because when I set the
>>>> totalItems as a static number.. it works. But how I said earlier.. the
>>>> number of items will increase itself then I can't use the number 12 no
>>>> longer.
>>>>
>>>> Am Freitag, 30. Januar 2015 18:21:18 UTC+1 schrieb Kristijan Pokas:
>>>>>
>>>>> It doesn't work.
>>>>>
>>>>> I have a dynamic array from the backend server. So I can't set a
>>>>> static number in totalItems?! I need the number of the list from the
>>>>> backend.. when I set $scope.totalItems.length then I have the dynamic
>>>>> number of items.. it is currently 12.. but in future the number of items
>>>>> can increment itself.
>>>>>
>>>>> but the totalItems.length is NOT a INT.. I think it's a string. That
>>>>> is the problem why the list won't output correctly. Do you know what I
>>>>> mean?
>>>>>
>>>>> The array consists of objects which have more items..
>>>>>
>>>>> for example: {id: ..., firstname: ..., lastname: ... etc.} {....} and
>>>>> so on.
>>>>>
>>>>> Am Freitag, 30. Januar 2015 17:16:52 UTC+1 schrieb Nicholas Smith:
>>>>>>
>>>>>> Sorry about that I forgot offset wasn't part of stock angular
>>>>>> filters. You'll need to add it. Here's a plnkr showing your code
>>>>>> working
>>>>>> with the filter.
>>>>>>
>>>>>> http://plnkr.co/edit/QLH5beg2QMEVg9h5Fx2R?p=preview
>>>>>>
>>>>>> The filter to add will look like this:
>>>>>>
>>>>>> angular.module('YourAppModule').filter('offset', function () {
>>>>>> return function (input, offset) {
>>>>>> return (input instanceof Array) ? input.slice(+offset) : input;
>>>>>> }
>>>>>> })
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Friday, January 30, 2015 at 10:07:46 AM UTC-6, Kristijan Pokas
>>>>>> wrote:
>>>>>>>
>>>>>>> The problem is, that the $scope.list.length isn't an int value.
>>>>>>>
>>>>>>> I have to convert this but I don't know how..
>>>>>>>
>>>>>>> The items are coming from a backend server. There are object items.
>>>>>>>
>>>>>>> Am Freitag, 30. Januar 2015 16:58:20 UTC+1 schrieb Nicholas Smith:
>>>>>>>>
>>>>>>>> Does your $scope.list actually contain all the items not just one
>>>>>>>> page of results?
>>>>>>>>
>>>>>>>>
>>>>>>>> On Friday, January 30, 2015 at 9:55:36 AM UTC-6, Kristijan Pokas
>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> I've tried your solution but then it outputs no items. :(
>>>>>>>>>
>>>>>>>>> Am Freitag, 30. Januar 2015 16:23:14 UTC+1 schrieb Nicholas Smith:
>>>>>>>>>>
>>>>>>>>>> You need to specify an offset as a starting point in your
>>>>>>>>>> ng-repeat directive.
>>>>>>>>>>
>>>>>>>>>> <tr ng-repeat="model in list | offset: currentPage*itemsPerPage
>>>>>>>>>> | limitTo: itemsPerPage">
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Friday, January 30, 2015 at 8:41:18 AM UTC-6, Kristijan Pokas
>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>> $scope.totalItems = $scope.list;
>>>>>>>>>>>
>>>>>>>>>>> When I output my totalItems in the brackets
>>>>>>>>>>> {{totalItems.length}} then it outputs 12 (thats the currently
>>>>>>>>>>> number of
>>>>>>>>>>> items).
>>>>>>>>>>>
>>>>>>>>>>> I think the paginator see this as a string and not as a number,
>>>>>>>>>>> because when I'm giving my totalItems a static number then it
>>>>>>>>>>> outputs the
>>>>>>>>>>> correct Pagination Numbers (in my example there are 3 pages).
>>>>>>>>>>>
>>>>>>>>>>> How can I convert this in an Int value? I tried with parseInt
>>>>>>>>>>> but it doesn't work.
>>>>>>>>>>>
>>>>>>>>>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "AngularJS" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/angular/zkJe4qlIjXA/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.