pagination directive

964 views
Skip to first unread message

klvm...@gmail.com

unread,
Dec 31, 2012, 4:07:13 AM12/31/12
to ang...@googlegroups.com
i am trying to create a basic directive for pagination links but am stuck with an 
Unexpected token :
error
please help... 

Joshua Miller

unread,
Dec 31, 2012, 4:56:21 AM12/31/12
to angular
Hi!

I'm not sure what your code was supposed to do as it was very long and contained a mixture of jQuery and Angular, but the error is caused by a typo on this line:

link $('<a href="javascript::void(0)" class="page-link">' (options.text'</a>');

There should not be two colons.

Josh


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
 
 

klvm...@gmail.com

unread,
Dec 31, 2012, 5:34:42 AM12/31/12
to ang...@googlegroups.com
Thank you josh,
I'm not sure what your code was supposed to do as it was very long and contained a mixture of jQuery and Angular, but the error is caused by a typo on this line:
it is meant to be a directive that generates pagination links given the number of pages and the current page number.

link $('<a href="javascript::void(0)" class="page-link">' (options.text'</a>');
There should not be two colons.
removing the semicolon fixed the error, but the bi-directional binding '=' does not seem to work.
any ideas of how i can fix this?
here is the new fiidle http://jsfiddle.net/kelvo/zZURe/7/

Pawel Kozlowski

unread,
Dec 31, 2012, 5:56:26 AM12/31/12
to ang...@googlegroups.com
Hi!

I agree with Josh that your directive could be streamlined by ditching
jQuery usage.
Pagination is a relatively simple directive and could be done in
AngularJS alone making it lighter.

Also, you are doing a lot of DOM manipulations in the directive
itself. Probably the better idea is to use a template. This has 2
advantages:
- removes markup clutter from the directive's JavaScript code
- allows people to customize the pagination directive.

As an inspiration you can have a look at the excellent pagination
directive written by Peter in the angular-ui/boostrap repository:
https://github.com/angular-ui/bootstrap/tree/master/src/pagination

it has an externalized templates
(https://github.com/angular-ui/bootstrap/tree/master/template/pagination)
which use a bootstrap markup but could be changed to use any other
HTML/CSS.

In short: you would get much more benefit by abandoning jQuery and
sticking to pure AngularJS-way.

Cheers,
Pawel
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> angular+u...@googlegroups.com.
> Visit this group at http://groups.google.com/group/angular?hl=en-US.
>
>



--
Question? Send a fiddle
(http://jsfiddle.net/pkozlowski_opensource/Q2NpJ/) or a plunk
(http://plnkr.co/)
Need help with jsFiddle? Check this:
http://pkozlowskios.wordpress.com/2012/08/12/using-jsfiddle-with-angularjs/

Looking for UI widget library for AngularJS? Here you go:
http://angular-ui.github.com/

klvm...@gmail.com

unread,
Dec 31, 2012, 6:26:56 AM12/31/12
to ang...@googlegroups.com
i finally got it working but i think ill consider peters directive
here is the working fiddle http://jsfiddle.net/kelvo/zZURe/17/

Pawel Kozlowski

unread,
Dec 31, 2012, 6:32:52 AM12/31/12
to ang...@googlegroups.com
Hi!

On Mon, Dec 31, 2012 at 12:26 PM, <klvm...@gmail.com> wrote:
> i finally got it working but i think ill consider peters directive

Yeh, I would advise to do so. Just noticed in your directive the usage
of $timeout which normally shouldn't be needed and it can create
flickering effect with your directive.

Cheers,
Pawel
Reply all
Reply to author
Forward
0 new messages