Embedding AngularJS view -
i have angularjs application believe pretty typical (alike many of examples).
<html ng-app="myapp" ... <body> ... <div class="main" ng-view></div> ...
there's $routeprovider
i've set whole lot of when
s direct users view (template partial controller), such as:
$routeprovider.when('/incident/:identifier', {templateurl:'incident.html', controller:"incidentctrl"});
this working fine. users can go , forth between views.
now, let's have view "incident". has form properties of "incident". (you can change values in form , "save", besides point here.) have following requirements:
- "add work order" button below existing form
- when button clicked, form (partial) loaded below existing form enter details new "work order"
- "save" button part of loaded form (partial) save new "work order"
- the form (partial) closed, unloaded or @ least visually removed
- possibly go 2. repeat (to add subsequent "work orders")
for form loaded below existing form reuse existing template partial subsequent controller, i'm using top-level ng-view
elsewhere. i've gone down few roads implement @ no avail; ng-include
seems not work, pretty static , not allow of lifecycle on embedded element. also, seems hard load dynamically, means it's gonna loaded before "add work order" button ever clicked. point me workable strategy? goal promote reuse of existing template partial , controller, without having user move between views. appreciated.
edit: elaborating: i'm not happy (yet) ng-include
ideas i've seen far, since:
- there bunch of them if had more single kind of view embed. loaded ahead of being shown no reason; overkill
- i not know how parameterize embedded views in same way can pass
$routeparams
$routeprovider
- i uncomfortable of sharing between parent , child scopes
- i have no way cleanly recreate controller subsequent "adds"
i try address concerns ng-include
there bunch of them if had more single kind of view embed. loaded ahead of being shown no reason; overkill
ng-if
can here. directive not load dom till condition becomes true. , destroys dom when condition becomes false. like
<div ng-if='conditionwhenthepartialshouldbeshown'> <ng-include src='templatename' ng-init='model=parent.someproperty'/> </div>
i not know how parameterize embedded views in same way can pass $routeparams $routeprovider
you can use ng-init
passing parameters when view loaded. check documentation
i uncomfortable of sharing between parent , child scopes
ng-init
can here again. can create property on child scope , pass parent scope value in ng-init
i have no way cleanly recreate controller subsequent "adds"
ng-if
you.
Comments
Post a Comment