AngularJS: Determining Template based on Select Control -
i thrown loop scope creep/change on project.
initially there 6 buttons on page (with other stuff) triggering routes 6 different add new ... forms. had buttons wired routes , working.
on friday, uix leader decided landing page complex , convinced stakeholders single "add new request" button needed leading drop down wherein user choose correct form.
so template looks this:
<form> <div class="row"> <div class="form-group col-lg-12"> <label for="requesttype">what type of request create? <span class="required">*</span> </label> <select class="form-control" name="requesttype" ng-model="requesttype" ng-change="new_form_select()"> <option value="0">please select ...</option> <option value="1">it web task</option> <option value="2">sap task</option> <option value="3">email campaign</option> <option value="4">third party suppression</option> <option value="5">report request</option> <option value="6">other / i'm not sure</option> </select> </div> </div> </form>
i have templates of webtask.html, saptask.html, campaign.html, suppression.html, report.html, generalrequest.html.
i realized when got far don't have clue next. should put of forms on same page hidden , show them based on selection (can that?) or should make select sort of page jump menu , load applicable form when selected (do in controller?)
omg, lost!
needless say, first angular project ... used use pure jquery , learning angularjs.
any guidance appreciated!!!
i can't solve problem can guide through main steps of simple solution:
- take @ angular-ui-router
the method called on select ng-change redirect state selected form:
<select class="form-control" name="requesttype" ng-model="requesttype" ng-change="new_form_select()"> <option value="0">please select ...</option> <option value="webtask">it web task</option> <option value="saptask">sap task</option> .... </select> $scope.new_form_select = function() { if(requesttype) { location.href = '#/' + requesttype; } }
you need define states , link templates. angular-ui-router has few examples in it's documentation like:
.state('webtask', { url: "/webtask", templateurl: "templates/webtask.html", controller: function() { } }) .state('saptask', { url: "/saptask", templateurl: "templates/saptask.html", controller: function() { } }) // idea..
now need add markup these templates placed in page. again angular-ui-router has few examples on how can done:
<body> <!-- select here --> <!-- selected template appear here --> <div ui-view></div> </body>
of course need add $stateprovider, $urlrouterprovider in config main controller explained in angular-ui-router page.
Comments
Post a Comment