npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wp-angularjs

v1.2.3

Published

WP-API client for AngularJS

Downloads

6

Readme

wp-angularjs

Build Status

A WP-API Client for AngularJS.

Getting Started

$ npm install wp-angularjs --save
<!DOCTYPE html>
<html ng-app="wp">
<head>
	<meta charset="UTF-8">
	<link rel="stylesheet" type="text/css" href="path/to/style.css">
	<title>WP-Angular</title>
	<script src="path/to/angularjs/1.5.0/angular.min.js"></script>
	<script src="path/to/angularjs/1.5.0/angular-resource.min.js"></script>
	<script src="path/to/angularjs/1.5.0/angular-sanitize.min.js"></script>
	<script src="path/to/wp-angular.min.js"></script>
</head>
<body>
	<have-posts api-root="http://example.com/wp-json/wp/v2"
						post-type="posts" offset="0" per-page="5">
		<header class="entry-header">
			<the-post-thumbnail size="post-thumbnaiil"></the-post-thumbnail>
			<h1 class="entry-title"><the-title></the-title></h1>
			<div class="entry-meta">
				<the-date format="yyyy/mm/dd"></the-date>
			</div>
		</header>
		<div class="entry-content">
			<the-content></the-content>
		</div>
	</have-posts>
</body>
</html>

Demo: http://miya0001.github.io/wp-angularjs/demo/

Requires

Recommended:

API Reference


<have-posts>

The havePosts directive is a WordPress loop.

Attributes

| Attribute | Type | Details | |-----------|--------|----------------------------------------------------------------| | api-root | string | Root url of the API. e.g. http://example.com/wp-json/wp/v2 | | post-type | string | posts or pages or media or custom post type. | | per-page | number | The number of posts per page. Default is 10. | | offset | number | The number of post to displace or pass over. Default is 0. | | post-id | number | The ID of the post. | | filter | object | The object of the filter. |

Example

<have-posts api-root="http://example.com" post-type="posts">
  <h2 class="entry-title"><the-title></the-title></h2>
  <div class="entry-content"><the-content></the-content></div>
</have-posts>

If you want to get single post, you can use post-id.

<have-posts api-root="http://example.com" post-type="posts" post-id="123">
  <h2 class="entry-title"><the-title></the-title></h2>
  <div class="entry-content"><the-content></the-content></div>
</have-posts>

You can pass filters to WP_Query through via the filter argument.

<have-posts api-root="http://example.com" post-type="posts"
           filter="{ order: 'ASC', cat: 123 }">
  <h2 class="entry-title"><the-title></the-title></h2>
  <div class="entry-content"><the-content></the-content></div>
</have-posts>

<the-title>

Displays the post title of the current post. This tag must be used within The <have-posts>.

Attributes

| Attribute | Type | Details | |-----------|--------|----------------------------------------------------------------| | href | string | Specify a link URL like #/app/posts/:id. |

Example

<the-title></the-title>

Then:

<div class="the-title">Hello World</div>

If you need a link to the post on your app. Please add href as attribute.

<the-title href="#/posts/:id"></the-title>

Then:

<div class="the-title"><a href="#/posts/123">Hello World</a></div>

:id is a placeholder of the post's id. You can use :slug as post's slug too.

<the-title href="#/posts/:slug"></the-title>

Then:

<div class="the-title"><a href="#/posts/hello-world">Hello World</a></div>

<the-content>

Displays the post content of the current post. This tag must be used within The <have-posts>.

Example

<the-content></the-content>

Then:

<div class="the-content"><p>Hello World</p></div>

<the-post-thumbnail>

Displays the post thumbnail of the current post. This tag must be used within The <have-posts>.

Attributes

| Attribute | Type | Details | |-----------|--------|----------------------------------------------------------------| | size | string | Size of the post thumbnail. Default is full. | | href | string | Specify a link URL like #/app/posts/:id. |

Example

<the-post-thumbnail></the-post-thumbnail>

Then:

<div class="the-post-thumbnail"><img src="http://example.com/image.jpg"></div>

Uses size attribute.

<the-post-thumbnail size="full"></the-post-thumbnail>

Then:

<div class="the-post-thumbnail"><img src="http://example.com/image.jpg"></div>

If you need a link to the post on your app. Please add href as attribute.

<the-post-thumbnail href="#/posts/:id"></the-post-thumbnail>

Then:

<div class="the-post-thumbnail">
  <a href="#/posts/123"><img src="http://example.com/image.jpg"></a>
</div>

:id is a placeholder of the post's id. You can use :slug as post's slug too.

<the-post-thumbnail href="#/posts/:slug"></the-post-thumbnail>

Then:

<div class="the-post-thumbnail">
  <a href="#/posts/123"><img src="http://example.com/image.jpg"></a>
</div>

<the-id>

Displays the ID of the current post. This tag must be used within The <have-posts>.

Example

<the-id></the-id>

Then:

<div class="the-id">123</div>

<the-excerpt>

Displays the excerpt of the current post. This tag must be used within The <have-posts>.

Example
Place the code like following into your HTML.

<the-excerpt></the-excerpt>

Then you will get like following.

<div class="the-excerpt"><p>Hello World.</p></div>

<the-date>

Displays the date of the current post. This tag must be used within The <have-posts>.

Attributes

| Attribute | Type | Details | |-----------|--------|----------------------------------------------------------------| | format | string | See https://docs.angularjs.org/api/ng/filter/date |

Example
Place the code like following into your HTML.

<the-date></the-date>

Then you will get like following.

<div class="the-date">2016-02-16 13:54:13</div>

You can set format string like following. See https://docs.angularjs.org/api/ng/filter/date.

<the-date format="yyyy/MM/dd"></the-date>

Then you will get like following.

<div class="the-date">2016-02-16</div>

Creates your custom template tag

// Registers your module, you should import `wp`.
var myapp = angular.module( "myapp", [ "wp" ] );

// Creates a `<my-permalink></my-permalink>` as custom template tag.
// If you place it in your HTML,
// then you can get `<a href="#!/post/123">Hello</a>`.
myapp.directive( "myPermalink", [ '$sce', function( $sce ) {
	return{
		restrict:'E',
		replace: true,
		require : '^havePosts',
		compile: function( tElement, tAttrs, transclude ) {
			return {
				post: function postLink( scope, element, attrs, controller ) {
					var post = scope.$parent.post; // post object
					scope.post_id = post.id;
					scope.title = post.title.rendered;
				}
			}
		},
		template: "<a ng-href=\"#!/post/{{ post_id }}\">{{ title }}</a>"
	}
} ] );

Enables Infinite Scroll

Please load ngInfiniteScroll like following.

<script src="path/to/jquery.min.js"></script>
<script src="path/to/angularjs/1.5.0/angular.min.js"></script>
<script src="path/to/angularjs/1.5.0/angular-resource.min.js"></script>
<script src="path/to/angularjs/1.5.0/angular-sanitize.min.js"></script>
<script src="path/to/ng-infinite-scroll.min.js"></script>

Add infinite-scroll as a dependency.

angular.module( "app", [ "wp", "infinite-scroll" ] );

That's it.

How to contribute

$ npm install

Run testing.

$ npm test

Build js/wp-angular.min.js.

$ npm run build

Build documentation.

$ npm run docs