javascript - In AngularJS, how do I define a route which calls a specific method on a controller? -


i'm making crud page using angularjs, have add/edit/delete function. so, routes this:

/items (show list of items) /items/add (show add item form) /items/edit/:itemid (show edit item form) /items/del/:itemid (delete item) 

it seems have define different controller each of these 4 routes. e.g, additemctrl, edititemctrl, etc. however, doesn't seem optimal since additemctrl , edititemctrl going share deal of code. rather additemctrl, edititemctrl, etc, rather have 1 controller: itemctrl , , within route, i'd rather specify if want call itemctrl.add(), itemctrl.edit(), etc.

is there way accomplish or close it?

for angularjs, remember client side, url resource doesn't have directly related crud operation. recommend thinking of url route view, not operation.

for example, use these:

/items (show list of items)    /items/edit/:itemid (show edit item form) 

i not use these:

/items/add (show add item form) /items/del/:itemid (delete item) 

the reason not use urls above client side display /items/add resource? /items list right? same goes /items/del/:itemid

i make 2 controllers. 1 items controller (i.e. list of items) , item controller (i.e. single item). both should defer functionality central service manages items. service allow crud operations, , calling crud operations on server use routes have defined them.

as side note, have items controller, itemsedit controller, itemadd controller, , itemdelete controller. should keep controller thin. there call itemsservice methods. each of controllers provide specific view functionality , defer real work service.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -