Reputation: 514
I have been new to angular js.
My structure of Angular JS in MVC5 is in the picture below
I need to create a simple application that has CRUD for a single entity. So far, I have created only single controller in Angular folder.
I have put all the directives, filters and functions in the Website.js file. I need to create different pages like add/edit/details.
The CRUD operations are not only simple, but i have to put some extra logics in them. I need some process where either deletion, addition or updating in model do changes everywhere on the page.
Question
Should i place all the directives, functions to the same controller? Or i should create seperate files for each CRUD operation? Please guide me to the structure of this application.
Upvotes: 1
Views: 98
Reputation: 1326
You should create seperate files for directives, filters, services and controllers like this:
app(folder inside scripts)
----- controllers/(folder inside app)
---------- userController.js
---------- itemController.js
----- directives/(folder inside app)
---------- mainDirective.js
---------- otherDirective.js
----- services/(folder inside app where all the services will go)
---------- userService.js
---------- itemService.js
----- app.js(main file where you will declare angular module and other application configurations which are common)
Create module wise controllers and service like for user module i have created one service named userService and one controller userController now in this user controller i will implement all business logic related to user and all CRUD operations. It is good practice to specify all $http requests for CRUD in a service and call that service from controller.
Upvotes: 1