# ng2-comment 
A `Comment` module for Anonymous User, developed in Angular 2 Typescript with Math Captcha. 

## Features
1. Anonymous user can post a message.
2. Math Captcha to identify human user.
3. Comments and Replies in tree structure
4. Links for Upvotes and Downvotes
5. Pagination

## Demo

Here is the [demo](http://eastgate.in/ng2-comment-demo).

## Installation

>Assumptions:
>* An Angular 2 application is already available/installed.  (if not, [ng2-comment-demo](https://github.com/mohankumaranna/ng2-comment-demo) application may be installed).

>* Server side coding is already available/installed. (if not, a server side code available in backend folder of [ng2-comment-demo](https://github.com/mohankumaranna/ng2-comment-demo) application may be used.  **Server side code is developed on _nodejs_ and _mongodb_**)

_Step 1:_

`npm install ng2-comment --save`

_Step 2:_

In an application module, say `app.module.ts`, ensure following entries:  
```typescript
...  
import { HttpModule } from '@angular/http';  
import { CommentModule } from 'ng2-comment';  
...  
@NgModule ({  
	...  
	imports: [  
		...  
		HttpModule,
		CommentModule,  
		...  
	],  
	...  
})  
```


_Step 3:_
>Comment module needs to know, server address to save/retrieve comments.  Such input is made through a config object.  To avoid 'config' name collision with other such names in the application, an opaque token is used.

In a component file, say `app.component.ts`, ensure following entries:  
  
```  
import { OpaqueToken, Inject } from '@angular/core';  
...  
const APP_CONFIG_DATA = {  
	server_ip_addr: 'http://localhost:9090'  
}  
const APP_CONFIG_TOKEN = new OpaqueToken('config');  
...  
  
@Component ({  
	...  
	templateUrl: './app.component.html',  
	...  
	providers: [  
		{ provide: APP_CONFIG_TOKEN, useValue: APP_CONFIG_DATA }  
	],  
	...  
})  
export class AppComponent {  
	...  
	constructor( @Inject(APP_CONFIG_TOKEN) public config: OpaqueToken) {}  
	...  
}  
```
  
  
_Step 4:_
In the template file `app.component.html`, ensure following entry:  
  
```  
...  
<div class="col-xs-6 col-xs-offset-3">  
	<comment [config]=config></comment>  
</div>  
...      
```  
  
  
_Step 5:_
In the application's `index.html` file, include link to bootstrap css as ng2-comment uses it.  
  
```
<!DOCTYPE html>  
<html>  
  <head>  

	...  
  
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/	bootstrap.min.css">  
  
	...  
  
  </head>  
  <body>  
    <my-app>Loading...</my-app>  
  </body>  
</html>  
```
  

_Step 6:_
Run the server and client.  If `ng2-comment-demo` is installed, open a terminal to run server: `npm run server`, it runs at port 9090. Open another terminal to run client, `npm start` (ie. ng2-comment-demo), which runs at port 8080.

_Step 7:_
Open browser at url, say _http://localhost:8080_.  It shows the _Comment Form_ with list of comments.



## License
MIT
