angularjs - Angular.js sanity check: Services vs. Factories vs. Controllers... + Directives + Behavior -
this article when utilize directives, services , controllers, awesome , helpful is... has me massively confused think know ideal construction of angular application , need sanity check:
if have 2 inputs:
<label><span>false</span> <input type='radio' value='false' ng-value='false' ng-model='thing.exists' /> </label> <label><span>true</span> <input type='radio' value='true' ng-value='true' ng-model='thing.exists' /> </label> that part of larger form, in turn submit pull in form... , info later shown review, right way architect that:
tldr: flow of execution:
ng-model="thing.exist" ==> thing ==> thingcontroller ==> service ==> ...details... ==> getdetails? right have:
<div ng-controller='thingcontroller thing'> <fieldset> <label><span>doesn't exist</span> <input type='radio' value='false' name='checkexist' ng-value='false' ng-model='thing.exists' /> </label> <label><span>does exist</span> <input type='radio' value='true' name='checkexist' ng-value='true' ng-model='thing.exists' /> </label> </fieldset> <!-- ... --> </div> when input changes, should utilize ng-change on inputs trigger behavior (like add-on of directive)... right (via controller)?
i should utilize controller add together result of ng-change service? like... passing model value (thing.exists) service can utilize value later? complication factor- application uses require.js manage dependencies.
(actually, article isn't source of confusion- it's comments on article killing me.)
that's pretty much it, you've got right. thought following:
use directives managing user interface interactions , -some- state changes use controllers managing shallow set of logic use services sharing data, functionality , business logic.aka, on server - seek not load much controller.
angularjs architecture requirejs angularjs-service angularjs-controller
No comments:
Post a Comment