I'm building an app that basically calculates prices as you pick options. So basically it's a form with select options and as you go down the form, the app will process the price more refined and change the options for the other form fields.
Currently I have an API built out and in this processing, the app will need to hit the API a few different times. There will ultimately be 7-12 form fields that will make up the pricing options. While mapping out the controllers, I'm wondering what the best method to keep my processing organized. If I was doing this in a language like PHP I'd have different functions per form element and process each time the form changes.
In Angular, having one controller per view, I'm curious how you guys, the pro, would organize it..
In a non-specific language structure I'm thinking something like...
- select one has 5 options, user selects one.
- Using the data from step one, a calculation happens, hits the API and gets new options for select number 2. User selects options and process happens again.
So if my controller is say...
.controller("formController", function($scope){
//Function for when select one changes, listen for form change ng-change
function item1Change(){
//hit api with item1 value, get options for item2 and and load them into item2
}
function item2Change(){
//hit api with item2 value, get options for item3 and and load them into item3
}
})
To me, this seems very dirty as in I need to define stuff, it doesn't seem modular or segmented and I just feel that there's a better option. If you guys have any better ideas, let me know, THANKS!
$scopeI need control over", and then evaluate whether specific directives need their own controller, depending on the specific implementation of that directive within the scope in question.