niedziela, 1 grudnia 2013

Angularjs example MotoAds more advanced directive

Another thing we will add to MotoAds demo application is a feature which allows us to comment each advert. A good idea would be to realize this as AngularJS directive. It will look like in the picture below. We can see all added comment to advert, click on Comment link activate the comment form with Preview, Send and Cancel buttons.

The comment form we will realize as AngularJS directive. Before we start let's look at changed adverts.json, there is the additional comments field (array of comments):
Step 1
We create commenForm.html template which we use in directive:
Step 2
We in directives.js we create AngularJS directive:
Step 3
We add simple CommentController into controllers.js:
Step 4
We add simple newlines filter into filters.js:
Step 5
We comment-form directive into adverts.html and some additional code to list comments and activate the comment form: If you want to run this example on your computer, you can download sources from GitHub.

Any comment would be highly appreciated.

Brak komentarzy: