JavaScript Angular ui router dynamic url from server and API angular router dynamic path,angular router dynamic routes,angular router

I'm working on a web app which implements a wizard-like behavior. it uses an API to get the "wizard" steps. the API works in a way where you send a request with the current step and all previous answers so far > and get the next step (which also includes the step "name").

My problem is with the URL's of my app, since I need/want them to match the current step. BUT I don't know what is the "current" step until the user already routed to the page.

Example:

  1. user clicks on <a ui-sref="wizard({step: 'second'})"> ('second' is the current step)
  2. $stateProvider than invoke templateUrl e.g: http://whatever.com/getStep/second
  3. server gets the "second" param and passes to the API: current step: second & answer to first step 1 (for example) than receiving the next step HTML and name - lets say: "step_three" and some HTML
  4. Angular renders that HTML

problem with the example above: the user is now in http://myapp.com/#/wizard/second and the HTML that is shown is for the "step_three"

What I would like to do is a request to the server with does params & without routing > than according to the response set the state config: url and template and than "route" to that state. so that the user will be in http://myapp.com/#/wizard/XXX and see the HTML for XXX...

Is this possible? any ideas?

Answer:1

Simplistic approach (you could choose template on the fly in route if you would like)

.state('wizard', function() {
  url: 'wizard/:step',
  templateUrl: 'views/template/wizard.html',
  controller: function($scope, $stateParams, stepData) {
    $scope.step = $stateParams.step;
    $scope.stepData = stepData;
  },
  resolve: {
    stepData: function(api, $stateParams) {
      return api.getdata($stateParams.step);
    }
  }
})

in wizard html:

<div ng-show='step == "first"'>first data content</div>
<div ng-show='step == "two"'>second data content</div>
<div ng-show='step == "three"'>third data content</div>

if you want to avoid using ng-shows and prefer a different template depending on the route, then use the templateProvider instead of templateUrl:

templateProvider: function($stateParams) {
  return a valid string path to the template based on the $stateParams.step value
},
Answer:2

I am using modal window for the upload of images. But when click on upload I want to upload the images and then close the modal window. When I used data-dismiss="modal" as attribute in button it just ...

I am using modal window for the upload of images. But when click on upload I want to upload the images and then close the modal window. When I used data-dismiss="modal" as attribute in button it just ...

  1. close bootstrap modal with javascript
  2. close bootstrap modal jquery
  3. close bootstrap modal programmatically
  4. close bootstrap modal on submit
  5. close bootstrap modal on button click
  6. close bootstrap modal angular
  7. close bootstrap modal without jquery
  8. close bootstrap modal typescript
  9. close bootstrap modal on click outside
  10. close bootstrap modal in angular 7
  11. close bootstrap modal on click
  12. close bootstrap modal vuejs
  13. close bootstrap modal in react
  14. close bootstrap modal escape key
  15. close bootstrap modal angular 8
  16. close bootstrap modal on ajax success
  17. close bootstrap modal after ajax success
  18. close bootstrap modal automatically
  19. close bootstrap modal after save
  20. close bootstrap modal from angular component

I'm (poorly) attempting to create a simple page which loops between a clock + date, current weather, 7-day weather forecast, news and calendar events. Each of these 'items' are called upon using ...

I'm (poorly) attempting to create a simple page which loops between a clock + date, current weather, 7-day weather forecast, news and calendar events. Each of these 'items' are called upon using ...

  1. javascript loop call function
  2. javascript loop call stack
  3. callback for loop javascript
  4. javascript event loop call stack
  5. javascript loop ajax call
  6. javascript loop through call stack
  7. javascript for loop api call

I have an array of Javascript datetime objects which I want to display on a cal-heatmap. For this, i've done the following: var startTimes = [] //array of datetimes to show var cal = new CalHeatMap();...

I have an array of Javascript datetime objects which I want to display on a cal-heatmap. For this, i've done the following: var startTimes = [] //array of datetimes to show var cal = new CalHeatMap();...

The css inside the directive does not compile and leads to single color green itself. I want to have different colors for different values for the value identifier and the css color should change ...

The css inside the directive does not compile and leads to single color green itself. I want to have different colors for different values for the value identifier and the css color should change ...

  1. angularjs template inside directive
  2. angularjs template inside template
  3. angularjs load template inside controller
  4. angularjs function inside template
  5. angularjs variable inside template